While no tusing just one while loop?

$num = 0;
while ( ( $row = mysql_fetch_assoc($result) ) && $num++ <= 1000 ) {
        //do whatever you want and you'll get all results or max. 1000 lines ( 
whatever comes first )
}

Cheers,

        Tom

-----Original Message-----
From: Tim Streater [mailto:t...@clothears.org.uk] 
Sent: Thursday, August 11, 2011 11:22 AM
To: Jason Pruim
Cc: PHP General List
Subject: Re: [PHP] Problem with inserting numbers...

On 11 Aug 2011 at 02:22, Jason Pruim <pru...@gmail.com> wrote: 

> while ($num != "10000") {
>    while($row = mysql_fetch_assoc($result)) {
>        $padnum = number_pad($num, "4");
>        echo $row['areacode'] . "-" . $row['prefix'] . "-" . $padnum . "<BR>";
>        $num++;
>    }
>
>
> }

This is certain to fail. You've got the $num++ in the *inner* loop, and are 
checking its value in the *outer* loop. Think about it: suppose you enter the 
inner loop with $num being 9998. Suppose also that you then go round the inner 
loop 5 times. What is the value of $num when you then exit the inner loop in 
order to do the test against 10000 in the outer loop?

You need to rework that logic.

--
Cheers  --  Tim



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to