[Gloucs] mysql query in a php loop?

Guy Edwards gloucs at mailman.lug.org.uk
Tue Jun 17 21:24:07 2003


On Tue, 2003-06-17 at 21:13, Mick Brooks wrote:
[snip]
> When you say it stops after the first loop iteration, do you mean that....
> 
> > for ($i=0; $i <$num_results; $i++)
> >     {
> 
> ...it never gets here for a second time? If that's the case then
> $num_results is less than or equal to 1 on the second pass. Either it always
> was equal to one, or it gets reset somewhere in the loop. Where is
> $num_results set? Could anything change it in the loop?

no because if I do

for ($i=0; $i <$num_results; $i++)
    {
     echo "<h1>$i</h1>";

it outputs as it processes:
1
2
3
4
5

and stops where 5 is the first item in the database that matches all the
conditions and is affected by the MySQL update inside the loop. (1-4
being ditched as they aren't selected by bnum)

> It's a long shot, but if you really mean that it never enters the loop a
> second time, it must be because the condition is no longer true - it
> can't be anything else. This is good because you only need chase
> $num_results now....
> 
> >      $row = mysql_fetch_array($result);
> >      $req_num = htmlspecialchars(stripslashes($row["itemid"]));

hmmm... it seems to loop just fine until it hits a selected item. It
goes through all the if statements for the item and then does the SQL
query on it... but after that, quits from the loop. no error message and
loads the page footer below (e.g. just a require("htmlfooter.php"); )
without any problem.

> Otherwise, I'm sure someone else with more PHP foo will be along in
> a tick....

I should mention at this point a negotiable alcoholic reward for anyone
who can help.... 

-- 
Guy Edwards <guy_j_edwards@hotpop.com>