UBB.Dev
Posted By: Sheall While loops within while loops? - 05/09/2004 9:10 AM
I am rather stuck with this :/

Basically I need a while loop to run through the list of Bo_Keywords in my database. At each cycle of the first loop I need a second loop to cycle through all the post numbers that have the current Bo_Keyword associated with them. Finally, when the second loop finds a post number that corresponds to what is held in the variable "$paction" I want it to perform the echo and include as shown in the code below.

Where am I going wrong?

Code
<br /><br />                $query = "<br />		SELECT Bo_Keyword<br />		FROM  {$config['tbprefix']}Boards<br />		WHERE Bo_CatName  = 'Quests'<br />		ORDER BY Bo_Sorter ASC<br />	";<br />	$sti = $dbh -> do_query($query);<br /><br />                while(list($QKeyword) = $dbh -> fetch_array($sti)){<br />	<br />		$query = "<br />			SELECT B_Number<br />			FROM  {$config['tbprefix']}Posts<br />			WHERE B_Board  = '$QKeyword'<br />			AND   B_Approved = 'yes'<br />			AND   B_Parent = '0'<br />			ORDER BY B_Posted ASC<br />		";<br />		$sti = $dbh -> do_query($query);<br />		<br />		while(list($PostNum) = $dbh -> fetch_array($sti)){<br />			<br />			if ($paction == $PostNum) {<br />				echo "$widerightcolstart";<br />				include "{$palspath}/pals/questslistpal.php";		<br />			}	<br />		}<br />	}<br />
Posted By: Sheall Re: While loops within while loops? - 05/09/2004 10:33 AM
Eh, nevermind I added a flag to get around the problem.
Posted By: Rick Re: While loops within while loops? - 05/09/2004 5:06 PM
Not sure if this is going to behave as you are expecting. In your inner query you are reassigning $sti to the query results. $sti holds the results of your first query however. So when your inner query runs your first query will end up stopping since there will be no more results in $sti. You should use a different variable for one of those queries.
Posted By: Sheall Re: While loops within while loops? - 05/10/2004 12:33 AM
Ahh! No wonder!... thanks!

Oh well, I guess my workaround is still good though, since it will require less database queries
© UBB.Developers