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:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 7:56 PM
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.


Craig Vincent

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to