Jump to content

mysql_fetch_array while loop within another?


justravis

Recommended Posts

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>";
		}			
	}

Link to comment
Share on other sites

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!!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.