Te voy a dar mejor el codigo que yo uso para paginacion espero que te ayude
Código PHP:
<?php
class paginationClass{
var $page_num = 1;
var $page_pagination;
var $r_comment;
var $row_num;
var $numofpages;
var $range_min;
var $range_max;
var $page_min;
var $page_max;
var $range;
var $rowsPerPage;
var $s_comment;
var $s_comment_n;
function paginationClass($r, $rPP, $sc, $scn){
$this->range = $r;
$this->rowsPerPage = $rPP;
$this->s_comment = $sc;
$this->s_comment_n = $scn;
}
private function setComment(){
$this->page_num = (empty($this->page) ? $this->page_num : $this->page);
$offset = ($this->page_num - 1) * $this->rowsPerPage;
$this->s_comment = $this->s_comment . " LIMIT $offset, " . $this->rowsPerPage;
$this->r_comment = mysql_query($this->s_comment) or die(mysql_error());
$r_comment_n = mysql_query($this->s_comment_n) or die(mysql_error());
$this->row_num = mysql_num_rows($r_comment_n);
}
private function setValues(){
$this->numofpages = ceil($this->row_num/$this->rowsPerPage);
if($this->numofpages > 1){
$this->range_min = ($this->range % 2 == 0) ? ($this->range / 2) -1 : ($this->range - 1) / 2;
$this->range_max = ($this->range % 2 == 0) ? $this->range_min + 1 : $this->range_min;
$this->page_min = $this->page_num - $this->range_min;
$this->page_max = $this->page_num + $this->range_max;
$this->page_min = ($this->page_min < 1) ? 1 : $this->page_min;
$this->page_max = ($this->page_max < ($this->page_min + $rthis->ange - 1)) ? $this->page_min + $this->range - 1 : $this->page_max;
if ($this->page_max > $this->numofpages){
$this->page_min = ($this->page_min > 1) ? $this->numofpages - $this->range + 1 : 1;
$this->page_max = $this->numofpages;
}
$this->page_min = ($this->page_min < 1) ? 1 : $this->page_min;
}
}
private function setPagePagination(){
$self = $_SERVER["PHP_SELF"];
if($this->numofpages > 1){
$setPP = "<div>";
//[ « ]
if (($this->page_num > ($this->range - $this->range_min)) && ($this->numofpages > $this->range)){
$setPP .= "[ <a title='First' href='".$self."?page=1' class='title'><b>«</b></a> ]\n";
}
// [ Previous # ]
if ($this->page_num != 1) {
$setPP .= "[ <a title='First' href='".$self."?page=".($this->page_num-1)."' class='title'><b>Anteriores " . $this->rowsPerPage . "</b></a> ]\n";
}
// ...
if (($this->page_num > ($this->range - $this->range_min)) && ($this->numofpages > $this->range)){
$setPP .= " <b>...</b> ";
}
// [ # ]
for ($i = $this->page_min; $i <= $this->page_max; $i++) {
if ($i == $this->page_num)
$setPP .= "[ <b><font color=red>" . $i . "</font></b> ]\n";
else
$setPP .= "[ <a href='" .$self. "?page=" .$i. "' class='title'>".$i."</a> ]\n";
}
// ...
if (($this->page_num< ($this->numofpages - $this->range_max)) && ($this->numofpages > $this->range)) {
$setPP .= " <b>...</b> ";
}
//[ Next # ]
if ($this->page_num < $this->numofpages) {
$setPP .= "[ <a href='".$self."?page=".($this->page_num + 1) . "' class='title'><b>Siguientes " . $this->rowsPerPage . "</b></a> ]\n";
}
//[ » ]
if (($this->page_num< ($this->numofpages - $this->range_max)) && ($this->numofpages > $this->range)) {
$setPP .= "[ <a title='Last Info' href='".$self."?page=".$this->numofpages. "' class='title'><b>»</b></a> ]\n";
}
$setPP .= "</div>";
$this->page_pagination = $setPP;
}
}
function getPagePagination(){
$this->setComment();
$this->setValues();
$this->setPagePagination();
return array('r_comment' => $this->r_comment,
'row_num' => $this->row_num,
'page_pagination' => $this->page_pagination);
}
}
function pagination($r, $rPP, $sc, $scn){
$p = new paginationClass($r, $rPP, $sc, $scn);
$p->page = $_REQUEST["page"];
foreach($p->getPagePagination() as $k => $v){
if(trim($v)){
global $$k;
$$k = $v;
}
}
}
?>
Cambia el
& #37; por
%. Para Usarlo debes llamar la funcion de esta forma
Código PHP:
$sql_que_quiero_verificar = "SELECT * FROM TABLA";
$sql_que_verificara_numero_de_lineas = "SELECT * FROM TABLA";
/*
El primero es para que me muestre el rango que quiero mostrar
El segundo es para que me muestre cuantos "Rows" quiero que muestre
El tercero es mi sql principal
El cuarto es para ver cuantos "Rows" tiene la tabla seleccionada
*/
pagination(10, 10, $sql_que_quiero_verificar, $sql_que_verificara_numero_de_lineas);
while($row = mysql_fetch_assoc($r_comment)){
//codigo que quieras usar
echo $page_pagination;
}
Espero te sea útil