qwertyuiop Posted December 1, 2009 Share Posted December 1, 2009 I’m trying to join 2 tables via a common row in the tables and display the data. This is easy enough to do however the query I use is using the $_GET superglobal to display data whose id is the same as the value parsed by the URL. This seems to prevent me from using the same query to join the 2 tables based on their common rows. Table1 has a row called omg and table2 also has a row called omg. At the top of the page I want to display all data from table1 (all rows) only once and all data from table2 (all rows) uses a loop. So I call the same query twice like so… $sql = mysql_query(“SELECT * FROM table1 WHERE id = $id”); $row = mysql_fetch_array($sql); echo $row[‘omg’]; echo $row[‘row2’]; echo $row[‘row3’]; while($row = mysql_fetch_array($sql)) { // Here I want to display data from table2 when data from table1.omg = table2.omg } Am I going about this the right way? What I can’t get to work is the LEFT JOIN in the query. How do I link table1 and table2 based on the rows omg in the 2 tables and display that data in the loop? Thanks! Link to comment https://forums.phpfreaks.com/topic/183505-left-join-issue/ Share on other sites More sharing options...
cags Posted December 3, 2009 Share Posted December 3, 2009 Sounds like... SELECT a.*, b.* FROM table1 a JOIN table2 b ON a.omg=b.omg WHERE a.id=$id Link to comment https://forums.phpfreaks.com/topic/183505-left-join-issue/#findComment-970362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.