Jump to content

[SOLVED] how to join 2 querys


runnerjp

Recommended Posts

how could i join these 2 querys

$result1=mysql_query ("SELECT friendname FROM friends WHERE username='Admin' ORDER BY friendname"); 
$myrow1 = mysql_fetch_array ($result);
$friendname=$myrow1[friendname];
$result=mysql_query ("SELECT image FROM users WHERE friendname='$friendname'"); 

//loop statement 
while ($myrow = mysql_fetch_array ($result)) 
{ 
// this is the column 1 
if ($column == 1) 
{ 
printf("<tr><td><b></b>%s</td>",$myrow[image]); 

} 
else{ 
//this  is the column 2   
printf("<td><b></b>%s</td></tr>",$myrow[image]); 

} 
//increment the count 
$count += 1; 
// this is a modulus operator it gets the remainder of the equation 
$column = $count % 2; 
} 

?> 

 

so then i can echo out image??

Link to comment
https://forums.phpfreaks.com/topic/154053-solved-how-to-join-2-querys/
Share on other sites

select friends.friendname,users.image from friends JOIN users where users.friendname=friendname.friendname order by friendname

if it's possible that a user won't have an image then instead of JOIN you would use LEFT JOIN would return an empty field for user.

 

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.