MrLarkins.com Posted October 13, 2006 Share Posted October 13, 2006 while($main = mysql_fetch_array($main)){$id = $main['id'];$name = $main['name'];$email = $main['email'];$icq = mysql_query("SELECT icq_number FROM ibf_member_extra WHERE id = $id"); $icq_number = $icq['icq_number'];//then do html to display results}my question is about the mysql query within the while(), is this possible, or is there a better way? Link to comment https://forums.phpfreaks.com/topic/23848-is-this-possible/ Share on other sites More sharing options...
wildteen88 Posted October 13, 2006 Share Posted October 13, 2006 Whats the query used before the while loop. You shoud use a join instead if the two tables you are querying relate.If you use a join you dont need to do another (uneeded) query in the while loop. Link to comment https://forums.phpfreaks.com/topic/23848-is-this-possible/#findComment-108333 Share on other sites More sharing options...
MrLarkins.com Posted October 13, 2006 Author Share Posted October 13, 2006 sorry, here is the full part$main = mysql_query("SELECT id, name, email FROM ibf_members WHERE mgroup=4 ORDER BY id");while($main = mysql_fetch_array($main)){ //while you have records available from the SELECT query$id = $main['id'];$name = $main['name'];$email = $main['email'];$icq = mysql_query("SELECT icq_number FROM ibf_member_extra WHERE id = $id"); $icq_number = $icq['icq_number'];//then do html to display results} Link to comment https://forums.phpfreaks.com/topic/23848-is-this-possible/#findComment-108336 Share on other sites More sharing options...
wildteen88 Posted October 13, 2006 Share Posted October 13, 2006 Prehaps use this as the query for $main:[code]SELECT m.id, m.name, m.email, me.icq_numberFROM ibf_members as m, ibf_members_extra as me WHERE m.mgroup=4, m.id = me.id ORDER BY m.id[/code]It is untested however it should work. Link to comment https://forums.phpfreaks.com/topic/23848-is-this-possible/#findComment-108346 Share on other sites More sharing options...
Recommended Posts