justravis Posted September 9, 2008 Share Posted September 9, 2008 I could have sworn I hav done this b4...but the second while loop doesnt seem to go after the first iteration. Any thots? THANKS!! $acc_skr_r=mysql_query("SELECT acc_id FROM `acc-skr` WHERE skr_id=$_SESSION[skr_id] ORDER BY id", $db); $acc_q="SELECT accomodation.id, accomodation.name, inactive FROM accomodation, `acc-coor` WHERE `acc-coor`.coor_org_id=$_SESSION[coor_id] AND accomodation.id=`acc-coor`.acc_id ORDER BY accomodation.def_ord"; $acc_r=mysql_query($acc_q, $db); while($acc_list=mysql_fetch_array($acc_r)) { $checked=0; while($acc_skr=mysql_fetch_array($acc_skr_r)) { if($acc_list[id]==$acc_skr[acc_id]) { $checked=' checked'; break; } } } #Output all accomodations active or inactive seeker checked when active. if(!$acc_list[inactive] || $checked) { echo "\n<input type=checkbox name='acc[]' id='acc_$acc_list[id]' value=$acc_list[id] tabindex=" . $tabi++; echo "$checked><label for='acc_$acc_list[id]'>$acc_list[name]</label><br>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/ Share on other sites More sharing options...
dannyb785 Posted September 9, 2008 Share Posted September 9, 2008 try adding quotes around the row arrays so: if($acc_list[id]==$acc_skr[acc_id]) would be if($acc_list['id']==$acc_skr['acc_id']) Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/#findComment-637256 Share on other sites More sharing options...
justravis Posted September 9, 2008 Author Share Posted September 9, 2008 i put the 1st mysql_query (2nd while loop) WITHIN the first while loop..problem seems to b solved... BUT i purposely left the query out of the loop b4, so i wouldnt have to repeatedly query to the db...again, i thot i've done this b4... am i forgetting something? THANKS!!! Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/#findComment-637258 Share on other sites More sharing options...
dannyb785 Posted September 9, 2008 Share Posted September 9, 2008 Ok I see now. The way it's setup, the inner loop can only be looped once because you call the query outside the loop, and then you run thru it in the first iteration of the outer loop. So if the outer loop has more than 1 row fetched, then it won't have anything to go thru since the first iteration already did. So just as you said, you'll need to query each time in the outer loop to start the loop over again. Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/#findComment-637259 Share on other sites More sharing options...
justravis Posted September 9, 2008 Author Share Posted September 9, 2008 added quotes...no diff.. i didnt include some debug code in my first post: while($acc_skr=mysql_fetch_array($acc_skr_r)) { #Test echo "$acc_list[id]==$acc_skr[acc_id]<br>"; if($acc_list['id']==$acc_skr['acc_id']) { $checked=' checked'; break; } } ..so i know the while loop is not even running...the if statement does not seem to b the issue. Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/#findComment-637260 Share on other sites More sharing options...
justravis Posted September 9, 2008 Author Share Posted September 9, 2008 is there any way to reset the result array? (i've tried reset($acc_skr) with no luck) Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/#findComment-637261 Share on other sites More sharing options...
Mchl Posted September 9, 2008 Share Posted September 9, 2008 Try $acc_scr = NULL; Edit: Don't try that Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/#findComment-637285 Share on other sites More sharing options...
dannyb785 Posted September 9, 2008 Share Posted September 9, 2008 Oh yeah, i didn't think about that. I'd imagine if you put the result into $result then in each outer loop, set $result2 = $result and then do while($whatever = mysql_fetch_array($result2)) that way you're copying the result and not replacing it. See if that works Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/#findComment-637841 Share on other sites More sharing options...
sasa Posted September 9, 2008 Share Posted September 9, 2008 just before 2nd while loop insert lint mysql_data_seek($acc_skr_r, 0); Quote Link to comment https://forums.phpfreaks.com/topic/123378-mysql_fetch_array-while-loop-within-another/#findComment-637847 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.