Pagination

Discussion in 'PHP' started by crazyryan, Sep 29, 2007.

  1. #1
    Could someone point me to a simple pagination tutorial, simple in being not a huge long code at the end.

    I just need a Previous/Next type of pagination .. or if someone could write one for me that would be great.
     
    crazyryan, Sep 29, 2007 IP
  2. Kuldeep1952

    Kuldeep1952 Active Member

    Messages:
    290
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Search on Google for "php pagination" and select the
    one by Tony Marston. It seems to be ok.
     
    Kuldeep1952, Sep 29, 2007 IP
  3. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #3
    Okay, I tried that but I'm having troubles with this part:

    $query = "SELECT count(*) FROM table WHERE ...";
    $result = mysql_query($query, $db) or trigger_error("SQL", E_USER_ERROR);
    $query_data = mysql_fetch_row($result);
    $numrows = $query_data[0];

    I replaced table with my table name, but it doesn't seem to wanna work..

    EDIT: I removed WHERE ... and it seems to be working..
     
    crazyryan, Sep 29, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Can you specify "it doesn't seem to wanna work"?

    What happens?
     
    nico_swd, Sep 29, 2007 IP
  5. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #5
    I was getting mysql errors, but then I realised it was the query.

    Can anyone help me with getting it to show just Next/Previous when needed.
    I've got it down to:
    if ($pageno !== 1) {
    
       $prevpage = $pageno-1;
       echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
    } // if
    if ($pageno == $lastpage) {
       echo " NEXT LAST ";
    } else {
       $nextpage = $pageno+1;
       echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
    } // if
    PHP:
     
    crazyryan, Sep 29, 2007 IP
  6. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #6
    Sorry for the bump but anyone got any ideas? Need to complete this fairly soon
     
    crazyryan, Sep 29, 2007 IP