Forum Moderators: coopster
I hope this is clear enough, I really need to know the best way of doing this.
$query1 = "SELECT * FROM baskettable WHERE order_id = (your value here)";
$result1 = mysql_query($query1);
while ($row1 = mysql_fetch_array($result1)){
$query2 = "SELECT * FROM items WHERE item_id = $row1['item_id']";
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2)){
Do whatever you want with the info here. Call your item vars with $row2['fieldname'] and you can access your basket vars with $row1['fieldname'].
}
Hope it helps
}
SELECT * FROM baskettable LEFT JOIN items ON baskettable.item_id = items.id WHERE order_id = (value)
Not positive it's correct. Give it a shot and see what you get. I like to use phpmyAdmin for testing queries.
MySQL subqueries [mysql.com] can be quite handy but there is a dependency on which version of MySQL [mysql.com] you are running.
However, BirdMan has provided (IMHO) the best option for you here in his JOIN. Be aware that if for some reason there is no matching record for the items the row of returned data will have all it's item table columns set to NULL.