RE: [PHP] Problem with inserting numbers...
| From: | Dajka Tamás | Date: | Thu, 11 Aug 2011 09:29:59 +0000 |
| Subject: | RE: [PHP] Problem with inserting numbers... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314488@lists.php.net to get a copy of this message | ||
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@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 <pruimj@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