RE: Problem with inserting numbers...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:tim@xxxxxxxxxxxxxxxx] 
Sent: Thursday, August 11, 2011 11:22 AM
To: Jason Pruim
Cc: PHP General List
Subject: Re:  Problem with inserting numbers...

On 11 Aug 2011 at 02:22, Jason Pruim <pruimj@xxxxxxxxx> 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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux