pagination class not showing correct amt of pages

packlite

New Member
the problem with the class is that if i want to display 30 records at a time and i have 60 total records the pagination divs that shows the page numbers only shows page #1 and not page #2. i have tried to figure out how to fix it but i have given up. any help would greatly be apreciated.this is how i call attributes to the class.\[code\]$paginate = new Pagination;$paginate->pageName = "index.php"; //sets the page to use$paginate->perPage = 10; //show num of records per page$paginate->adjacents = 3; //current page adjacent to $paginate->sql = "select * from tbl_products"; //the main query$query = $db->query($paginate->getData());while($row = mysql_fetch_object($query)) { print $row->pName."<br/>";}$paginate->showPagination(); //shows the pagination div \[/code\]here is the class.\[code\]<?phpinclude_once("class.db.php");class Pagination { var $param; var $perPage; var $adjacents; var $start; var $sql; var $pageName; function __construct() { $this->db = new MysqlDB; $this->db->connect(); } function setParam() { if(isset($_GET['page']) && is_numeric($_GET['page']) && ($_GET['page'] > 0)) { $this->param = $_GET['page']; } else { $this->param = 1; } } function setIndex() { $this->setParam(); return $this->start = ($this->param * $this->perPage) - $this->perPage; } function showPagination($param1=null,$param2=null,$param3=null) { $qRows = $this->db->query($this->sql); $numRows = $this->db->num_rows($qRows); $numOfPages = ceil($numRows / $this->perPage); $param = $this->param; $pageName = $this->pageName; $string = ""; //set pagination parameters. if($param1 != null) { if(isset($_GET[$param1])) { $param1Value = http://stackoverflow.com/questions/3564206/$_GET[$param1]; $string .="&".$param1."=".$param1Value; } } if($param2 != null) { if(isset($_GET[$param2])) { $param2Value = http://stackoverflow.com/questions/3564206/$_GET[$param2]; $string .="&".$param2."=".$param2Value; } } if($param3 != null) { if(isset($_GET[$param3])) { $param3Value = http://stackoverflow.com/questions/3564206/$_GET[$param3]; $string .="&".$param3."=".$param3Value; } } print "<div class='pagination'>"; print "<a href='http://stackoverflow.com/questions/3564206/$this->pageName?page=1$string' class='previous-off'> First </a>"; // ---------------------------------------------------------------------------- // PRINT ALL PAGES TO THE LEFT // if(($param - $this->adjacents) > 1) { print "<span>...</span>"; $lowerLimit = $param - $this->adjacents; //print all on left side. for($i = $lowerLimit; $i< $param; $i++) { print "<a href='http://stackoverflow.com/questions/3564206/$pageName?page=$param = $i$string'> $i </a>"; } } else { //print all numbers between current page and first page. for($i = 1; $i < $param; $i++) { print "<a href='http://stackoverflow.com/questions/3564206/$pageName?page=$i$string'> $i </a>"; } } // ---------------------------------------------------------------------------- //print current page if(($param != 0) && ($param != $numOfPages)) { print "<span class='current'>$param</span>"; } // ---------------------------------------------------------------------------- //PRINT ALL PAGES TO THE RIGHT if(($param + $this->adjacents) < $numOfPages) { $upperLimit = $param + $this->adjacents; for($i=($param + 1); $i<=$upperLimit; $i++) { print "<a href='http://stackoverflow.com/questions/3564206/$pageName?page=$i$string'> $i </a>"; } print "<span>...</span>"; } else { //print all page numbers if out of padded range for($i = ($param + 1); $i<$numOfPages; $i++ ) { print "<a href='http://stackoverflow.com/questions/3564206/$pageName?page=$i$string'> $i </a>"; } } // ---------------------------------------------------------------------------- $lastPage = $numOfPages - 1; print "<a class='next' href='http://stackoverflow.com/questions/3564206/$pageName?page=$lastPage$string'> Last </li>"; print "</div>"; } function getData() { $query = $this->sql; $this->start = $this->setIndex(); return "$query LIMIT $this->start, $this->perPage"; } function errors() { $query = $this->sql; print "$query LIMIT $this->start, $this->perPage"."<br/>"; print "this->start ".$this->start."<br/>"; print "this->param ".$this->param."<br/>"; print "this->perPage ".$this->perPage."<br/>"; print "this->setindex() ".$this->setIndex()."<br/>"; }}?> \[/code\]
 
Back
Top