Thanks everyone for your help on this, this is the final code:

                    if ($num_pages >= 2) {
                            for ($i=0, $p=1; $i<$num_pages; $i++, $p++) {
                            $j = ($i==0) ? $i : $j+20;
                            printf("| <a href=\"test.php?type=all&page=%s\">Page 
%s</a> | ",
$j, $p);
                                }
                        }

Because of the way MySQL uses LIMIT, I found that using LIMIT 1, 20 and
LIMIT 21, 20 leaves out the 1st and 20th records. So I had to change $i to 0
to get them back. However, this left me with "Page 0 | Page 1" - not cool,
so I added $p into the loop, but started it at 1 so I'd have a variable to
use for correct page numbers.

Oh and I had to change $i<=$num_pages to just $i<$num_pages because with
$i=0, I was getting an extra iteration. What a learning experience!

Thanks again,

Jason Soza

-----Original Message-----
From: Richard Baskett [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 8:47 PM
To: Jason Soza; PHP General
Subject: Re: [PHP] Feelin' dumb...


Ok Im feeling dumb also now *hehe*  What I said about putting the $number
line below the printf line.. Donšt listen to me :)  Now that I know what you
want.. I know there is cleaner and better code, but it works :)

if ($num_pages >= 2) {
  for ($i=1; $i<=$num_pages; $i++) {
    $j = ($i==1) ? $i : $j+20;
    echo "| <a href=\"test.php?page=$j\">Page $i</a> | ";
  }
}

Rick

Be kind. Everyone you meet is fighting a hard battle - John Watson

> From: "Jason Soza" <[EMAIL PROTECTED]>
> Date: Fri, 17 May 2002 20:44:30 -0800
> To: "Richard Baskett" <[EMAIL PROTECTED]>, "PHP General"
> <[EMAIL PROTECTED]>
> Subject: RE: [PHP] Feelin' dumb...
>
> The 20 is inserted into a MySQL LIMIT query. Page 1 = LIMIT 1,20 to get
the
> first 20 records from 1, then Page 2 = LIMIT 21,20 to get the next 20,
etc.
>
> I think I see the error here.
>
>    if ($num_pages >= 2) {
>    for ($i=1; $i<=$num_pages; $i++) {
>    $number = ($i * 20) + 1;
>    printf("| <a href=\"test.php?page=%s\">Page %s</a> | ", $number,
> $i);
> }
> }
>
> Is ALMOST right... Except that the I need the first iteration to return 1.
> In this case, it returns 21, so the next iteration is 41. Follow me? I
need
> 1, 21, not 21, 41. Almost there I think, unfortunately, I need to jet.
I'll
> be thinkin' on this one while DJing, definitely!
>
> Thanks again for everyone's help.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to