Jump to content

LEFT JOIN Issue


qwertyuiop

Recommended Posts

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

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.