Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Anyone have an efficient solutions for pagination? I have to display a  
number of items but would like to paginate using only 10 lines of data  
on each page and provide navigation at bottom.

Any help appreciated..


Re: Pagination

Take a look at

Tony Marston

Quoted text here. Click to load it

Re: Pagination

contained the following:

Quoted text here. Click to load it

Here's a simple one for a guestbook.

Commenting is left as an exercise for the OP :-)


    $offset=(isset($_GET['offset']))?intval($_GET['offset']) :"";

    $sql = "SELECT COUNT(*) AS numrows FROM _guestbook
where status=1";
    //echo $sql;
    $result = mysql_query($sql) or die("could not run query");
    $rows=mysql_fetch_array($result)or die("could not fetch
    $rc = $rows['numrows'];

    echo ("<h3>Showing  rows 0 to $end out of $rc</h3>");
    $query = mysql_query("SELECT * FROM _guestbook where
status=1 ORDER BY `date` DESC LIMIT 0,$records_per_page");

    echo ("<h3>Showing  $r1 to $next out of " . $rc."</h3>");

    $sql="SELECT * FROM _guestbook where status=1 ORDER BY
`date` DESC LIMIT $offset,$records_per_page";
    $query = mysql_query($sql);

    echo "<hr>";
    echo '<table>';  
    while($row = mysql_fetch_array($query)){

      <td class='label'>Name:</td>
      <td><?php echo stripslashes($row['name']);?></td>

      <td class='label'>Location:</td>
      <td><?php echo stripslashes($row['location']);?></td>
      <td class='label'>Date:</td>
      <td><?php echo date("d/m/Y H:i",$row['date'])?></td>
      <td class='label'>Comments:</td>
      <td><?php echo stripslashes(str_replace("
      <td colspan='2'>
    echo "</table>";
    if($previous > -1 ){
    echo "<a
    echo($previous > -1)?" | ":"";
    echo "<a

Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs

Site Timeline