Jump to content

[SOLVED] Concerning MySQL JOIN and returned associative arrays.


JDB57

Recommended Posts

Hello, I was wondering if anyone could explain how the data from a MySQL JOIN query is returned in PHP. I have the following in my code:

 

$sql = "SELECT * FROM Customers JOIN Orders ON Customers.ID=Orders.userID";
$res = @mysql_query($sql,$connection) or die (mysqlerror());

while($arr = mysql_fetch_assoc($res))
{
echo $arr['Product'];
}

 

In the Orders table there is a column "Product". When I use a while loop, how do I call the Product?

 

Thanks in advance!

Thank you very much! I am in the process of learning MySQL and could not find that answer in any forum posting on any site. I have another question related to my code. If I wanted to have the results returned by the "Product" column, am I right in assuming that I just need to add "ORDER BY Product" to the end of the query or would it be "ORDER BY Orders.Product" instead?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.