What do you want the output to look like? I did this: $num_pages =120;
if ($num_pages >= 2) { for ($i=1; $i<=$num_pages; $i+=20) { $page = $i+1; printf("| <a href=\"test.php?page=%s\">Page %s</a> | ", $number, $page); } } And got this: | Page 2 | | Page 22 | | Page 42 | | Page 62 | | Page 82 | | Page 102 | Rick "If a man is called to be a streetsweeper, he should sweep streets even as Michelangelo painted, or Beethoven composed music, or Shakespeare composed poetry. He should sweep streets so well that all the hosts of heaven and earth will pause to say, "Here lived a great streetsweeper who did his job well." - Dr. Martin Luther King, Jr. > From: "Jason Soza" <[EMAIL PROTECTED]> > Date: Fri, 17 May 2002 20:09:55 -0800 > To: <[EMAIL PROTECTED]> > Subject: RE: [PHP] Feelin' dumb... > > 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 > To: Jason Soza; [EMAIL PROTECTED] > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php