Jump to content

[SOLVED] Concerning MySQL JOIN and returned associative arrays.


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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.