This example generates previous/next links but could be modified to make
links to page 1, 2, 3, 4, etc.

This code is not tested what so ever, but it should look something like
this:

-----

 $rows_to_show = 10;

 $total_rows = mysql_num_rows(mysql_query("select name, post from guestbook
order by id desc", $db));
 $result = mysql_query("select name, post from guestbook order by id desc
LIMIT $offset, $rows_to_show", $db);
 
 while ($myrow = mysql_fetch_row($result)) {
    echo "<TR><TD>$myrow[0]</TD></TR>\n";
    echo "<TR><TD>$myrow[1]</TD></TR>\n";
    ++$counter;
 }

 if ($offset > 0)
   echo "<a href=\"$PHP_SELF?offset=" . ($offset - $rows_to_show) .
"\">Previous</a>";

 if ($offset < $total_rows)
   echo "<a href=\"$PHP_SELF?offset=" . ($offset + $rows_to_show) .
"\">Next</a>";

-----
Call the page with myscript.php?offset=0

Good luck
Joakim


> -----Original Message-----
> From: James Taylor [mailto:[EMAIL PROTECTED]]
> Sent: Friday, February 22, 2002 8:40 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Guestbook question
> 
> 
> I have a really simple guestbook that allows someone to post 
> to the book, 
> then it displays all the entries.  Well, there are too many 
> entries now for 
> just one page and it looks kinda wacky, so I wanted to do 
> something where it 
> only displays 10 entries per page, then there are links for 
> pages say 11-20, 
> 21-30, etc.   I have no idea how to do this - I only know how 
> to limit the 
> number of entries per page.  So, the script that displays all 
> the entries 
> looks something like this:
> 
> 
> $counter = 0;
> $result = mysql_query("select name, post from guestbook order 
> by id desc", 
> $db);
> 
> while (($myrow = mysql_fetch_row($result)) && ($counter < 10)) {
>    echo "<TR><TD>$myrow[0]</TD></TR>\n";
>    echo "<TR><TD>$myrow[1]</TD></TR>\n";
>    ++$counter;
> }
> 
> 
> Well, that shows only the latest 10 alright, but what if I 
> wanted to show 
> entries 11-20?  I figure I could get the number of posts through 
> mysql_num_rows, I just can't piece it all together.  Any 
> suggestions would be 
> really helpful.
> 
> -- 
> 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

Reply via email to