Jump to content

double while loop question


mraza

Recommended Posts

Hi i am in a situation where i need to use two tables. please look at my code

 

$result= $db->dbrun('select * from table_user');
while($row = mysql_fetch_array($result)): 
echo $row['username'] . '<br />';
endwhile;

now my problem is i wants to get something from other table where user id match with $row['id'],

 

$result= $db->dbrun('select * from table_user');
while($row = mysql_fetch_array($result)): 
$query= $db->dbrun('select id from table_other where user_id =$row['id']');
while($user_row = mysql_fetch_array($query)): 
echo $row['username'] . ' - ' . $user_row['id'] . '<br />';
endwhile;
endwhile;

 

so my main question is is it ok to run $query within  a while loop because i cant run this query without $row['id'] which i gets after loop started or is there any other good way.

 

Thanks for answering.

 

Link to comment
https://forums.phpfreaks.com/topic/209505-double-while-loop-question/
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.