I know how to query two tables for the data I'm looking for, but I don't know how to display it. One table has customer information, the other table has orders placed by the customers.
I'm using this query:
SELECT customers.realname, orders.product FROM customers, orders WHERE customers.realname=orders.realname;
now do I write a WHILE statement?
How to display the data on a page?
looing to display it like this:
Customer:Product
Customer:Product
Customer:Product
All help much appreciated!
How do I display data from multiple tables?
Moderator: General Moderators
-
Stewsburntmonkey
- Forum Commoner
- Posts: 44
- Joined: Wed Aug 24, 2005 2:09 pm
There is actually nothing special to this as long as you just think about the array you will get from the server. Just don't try figuring out what the mySQL server is going through as that can be mind boggling in a lot of cases. 
Code: Select all
$mysql = "SELECT customers.realname, orders.product FROM customers, orders WHERE customers.realname=orders.realname";
$results = mysql_query( $mysql, $db )
or die ('Cannot execute mySQL query because: ' . mysql_error());
while($row = mysql_fetch_array($results)) {
print("$row[0]: $row[1]<br>\n");
}
mysql_free_result($results);