RE: [PHP] Feelin' dumb...
| From: | Jason Soza | Date: | Sat, 18 May 2002 04:09:55 +0000 |
| Subject: | RE: [PHP] Feelin' dumb... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-98215@lists.php.net to get a copy of this message | ||
Makes sense. Thanks!
Now... I have this little problem:
if ($num_pages >= 2) {
for ($i=1; $i<=$num_pages; $i++) {
$number = ($i * 20) + 1;
$page = $i+1;
printf("| <a href=\"test.php?page=%s\">Page %s</a> | ", $number,
$page);
}
}
I want $page to be $i + 1, but when I do $page = $i+1;, $i somehow gets
evaluated into the for() loop and an additional iteration is completed. So
basically if I do it this way, I get I'll get 1, 21, 41, when really only 1
and 21 are valid. If I put in $page = $i++; it works correctly, but $i is 1
when I want it to be two. If I take out $page = and put in $i where $page is
in the printf() statement, I get the extra iteration again. Any ideas?
-----Original Message-----
From: Craig Vincent [mailto:2bunnyhop@rogers.com]
Sent: Friday, May 17, 2002 7:56 PM
To: Jason Soza; php-general@lists.php.net
Subject: RE: [PHP] Feelin' dumb...
> I wonder why the other suggestions weren't working. They seemed logical
> enough, I even tried variations of your suggestion, first I tried:
>
> for ($i=1; $i<=$num_pages; $number = $i + 20) {}
> for ($i=1; $i<=$num_pages;) { $number = $i + 20; }
The problem with these two statements was that the loop would be indefinate.
Without the third option $i is never incremented (unless you manually
increment it from within the loop). So with your examples $i would always
be 1 and would therefore always be <= $num_pages unless $num_pages was zero
or negative.
Sincerely,
Craig Vincent
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php