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
Share on other sites

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.