SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    1 Post(s)
    0 Thread(s)

    How to add a pager to the page with php?

    I'm new to PHP and I'd like to add a pagination function to the page.

    I have this piece of code:

    $result = mysql_query( "select title from post LIMIT 5 OFFSET 0");
    while ($row = mysql_fetch_object($result)) {
        echo $row->title;
    $total is all the rows.

    I'd like to show only five post titles per page. If I want to add a pager to this page, how do I do this? E.g: the URL is

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Atlanta, GA, USA
    71 Post(s)
    0 Thread(s)
    well it shouldnt be .html or the PHP engine shouldnt be parsing it

    pagination can be calculated with as little as a single URL variable;

    From there you can calculate your start point ((page - 1) * sizeofpages) [assuming you're using page 1 as your 0-index]
    your size is defined by the code;
    The resulting query would be SELECT ... LIMIT <startpoint>,<sizeofpage>

    To generate the nav takes a bit more calculation, but there's plenty of pagination scripts out there already written...
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts