WEB PHP pagination class

Discussion in 'OT Technology' started by 96, May 28, 2008.

  1. 96

    96 Merry Christmas :D

    Joined:
    Oct 30, 2001
    Messages:
    16,073
    Likes Received:
    0
    Location:
    San Diego
    Does anyone have a good pagination class written in PHP?

    I can't be bothered to make my own right now :hsd:
     
  2. 96

    96 Merry Christmas :D

    Joined:
    Oct 30, 2001
    Messages:
    16,073
    Likes Received:
    0
    Location:
    San Diego
    yeah, want a PHP one.

    I can use one I wrote for work, but it's ugly and wanted to see if there were any better plug-and-play ones
     
  3. Josh

    Josh Guest

    I think it would be hard to find one that is plug and play since it is going to depend on the specific fields and rows in your database. I'll paste a sample from one I've wrote though... this isn't exactly clean either


    Code:
    
    $showperpage = 20;
    
    
    
    
    
    
    $ustring = "select count(id) from bored where type='pictures'";
    
    $mysqlquery = mysql_query($ustring);
    if (!(mysql_num_rows($mysqlquery) == 0)) {
     $row = mysql_fetch_array($mysqlquery);
     $count = $row[0];
    }
    
    
    $start = $_REQUEST["start"];
    if(empty($start)){
    $start = "0";
    } else {
    $start = ($start-1) * $showperpage;
    }
    
    if($start<0){
    $start="0";
    }
    
    
    $mysqlquery = mysql_query("SELECT `id`,`votes`,`points`,`category`,`text`,`link`,`hits`,`date`,`time`,`name`,`path` FROM `bored` WHERE type='pictures' order by id desc limit $start, $showperpage");
     
    
      while ($row = mysql_fetch_array($mysqlquery)) {
    //youcode
    
    }
    
    
    
    
    $pages = $count / $showperpage;
    
    $intpages =  (intval($pages));
    
    if($pages>$intpages){
    $pagecount = $intpages + 1;
    } else {
    $pagecount = $intpages;
    }
    
    //echo "Count: $count , Pages: $pagecount <br>";
    
    
    if($pagecount>1){
    echo "<center><ul class=\"nav\">";
    for ($i = 1; $i <= $pagecount; $i++) {
    //$start = $i - 1;
    //$start = $start * 4;
    $start = $i;
      echo" <a href=/page.php?page=$start><li>Page $i</li></a>";
    }
    echo "</ul></center>";
    }
    
    
     
  4. lukin87

    lukin87 New Member

    Joined:
    Jan 11, 2008
    Messages:
    135
    Likes Received:
    0
    man... it would be quicker to write one than to edit someone elses code.
     

Share This Page