PDA

View Full Version : How to Display matching Data


bakraa
01-21-2006, 06:53 AM
hi i am new to php and stuck in this situation please help..

there are two table in my database

i want to display matching fields from one data base tabel to the other in PHP

like there is a colume in [Table A] named (user)

similarly there is a colume in [Table B] named (user)

now if in the user field of [Table A] someone puts G22 i want to see all the rows matching the G22 in the [Table B]

___________________________________________________________________________

[Table A]
----------------------------------
| User | Name | Pass |
------------ ----------------------
| G11 | John | rerr |
| G25 | Smith | rtfr |
| G6 | Tom | wer |
| G30 | Joe | ere |
-----------------------------------

[Table B]
---------------------------------------
| Loss | Amount | User | Profit |
---------------------------------------
| 200 | 5656 | G25 | 78 |
| 300 | 5656 | G25 | 65 |
| 523 | 7878 | G11 | 67 |
| 334 | 6788 | G6 | 55 |
| 665 | 7888 | G30 | 35 |
| 778 | 7878 | G14 | 67 |
| 655 | 4545 | G6 | 88 |
| 544 | 3434 | G25 | 88 |
| 434 | 6787 | G14 | 89 |
| 334 | 3455 | G11 | 89 |
| 343 | 7787 | G30 | 55 |
| 23 | 8787 | G6 | 65 |
----------------------------------------

_________________________________________________
---------------------------------------------------------
User Registration Page.PHP
---------------------------------------------------------

Enter Name : [ Adam ]
Enter Password:[ **** ]
Enter User : [ G14 ]

<Register>

---------------------------------------------------------

________________________________________________
----------------------------------------------------------
User Login Page.PHP
----------------------------------------------------------

Enter Name : [ ]
Enter Password:[ ]

<Submit>
----------------------------------------------------------

_________________________________________________

----------------------------------------------------------
User Info Page.PHP
----------------------------------------------------------

Welcome Adam you are G14

| Loss | Amount | Profit |
-----------------------------
| 778 | 7878 | 67 |
| 434 | 6787 | 89 |

-----------------------------------------------------------
(data related to G14 only )

_______________________________________________________________________________

I hope that I have made my self clear...

I don't need any help regarding the registration or submit of the forms... this is already heppening...

The only problem i am having is in the "User Info Page" where i have to show the information matching the fields.

Thanks !

bakraa
01-21-2006, 06:57 AM
also this is the code for the user info page , but as you can see it is not dynamicly showing any result, but i have entered G11 in the code to display the info about the user G11 ...
thats the problem...

<?php require_once('Connections/basic.php'); ?>
<?php
mysql_select_db($database_basic, $basic);
$query_Record = "SELECT * FROM data where 'user' LIKE '_G11_'";
$Record = mysql_query($query_Record, $basic) or die(mysql_error());
$row_Record = mysql_fetch_assoc($Record);
$totalRows_Record = mysql_num_rows($Record);
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Profile Info</title>
</head>

<body>
<table border="1">
<tr>
<td>user</td>
<td>Loss</td>
<td>Profit</td>
<td>Amount</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Record['user']; ?></td>
<td><?php echo $row_Record['loss']; ?></td>
<td><?php echo $row_Record['profit']; ?></td>
<td><?php echo $row_Record['amount']; ?></td>

</tr>
<?php } while ($row_Record = mysql_fetch_assoc($Record)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($Record);
?>

bakraa
01-22-2006, 08:27 PM
anyone please... help!!!

degsy
01-23-2006, 03:32 PM
Checkout the JOIN statement
http://www.w3schools.com/sql/sql_join.asp