[Gloucs] mysql query in a php loop?

Mick Brooks gloucs at mailman.lug.org.uk
Tue Jun 17 21:09:00 2003


On Tue, Jun 17, 2003 at 08:17:49PM +0100, Guy Edwards wrote:

Hi Guy,

> I've got a mysql/php coding problem.
> my bit of PHP code goes something like this:

<snip>

> problem is, say there are 3 results that are to be processed (match the
> criteria) , as soon as it hits the first one, it stops doing the loop.

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?

It's a long shot, but if you really mean that it never enters the loop a
second time, it must be because the condtion 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"]));

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

-- 
Mick Brooks
michael.brooks@physics.ox.ac.uk