JDB57 Posted October 29, 2008 Share Posted October 29, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/130513-solved-concerning-mysql-join-and-returned-associative-arrays/ Share on other sites More sharing options...
trq Posted October 29, 2008 Share Posted October 29, 2008 Exactly as you have done. Quote Link to comment https://forums.phpfreaks.com/topic/130513-solved-concerning-mysql-join-and-returned-associative-arrays/#findComment-677104 Share on other sites More sharing options...
JDB57 Posted October 29, 2008 Author Share Posted October 29, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/130513-solved-concerning-mysql-join-and-returned-associative-arrays/#findComment-677149 Share on other sites More sharing options...
asmith Posted October 29, 2008 Share Posted October 29, 2008 Orders.product but you need "desc" or "asc" after that. Quote Link to comment https://forums.phpfreaks.com/topic/130513-solved-concerning-mysql-join-and-returned-associative-arrays/#findComment-677168 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.