La clase completa.
Código PHP:
Ver original# --- Paginador
class Cm_Paginador{
# --- Configuracion
var $Posicion,$Botones,$Base,$Article,$Order,$Mysql,$Query,$Exect,$Cant,$Paginas,$Comming,$Consulta,$Estructura;
# --- Mysql
public function _Mysql($Mysql,$base,$article,$orden,$Posicion){
# --- Mysql
$this->Base = $base;
$this->Order = $orden;
$this->Article = $article;
$this->Posicion = $Posicion;
$this->Mysql->Conectar();
$this->Query = "SELECT * FROM ".($this->Base);
$this->Exect = $this->Mysql->Consulta($this->Query);
# --- Condicionales
$this->Cant = $this->Mysql->Reg_Num($this->Exect);
$this->Paginas = ceil($this->Cant/$this->Article); $this->Comming = $this->Article*$this->Posicion;
$Desde = $this->Posicion*$this->Paginas;
# --- Consulta
$this->Consulta = $this->Mysql->Consulta($this->Query.' ORDER BY id '.$orden.' LIMIT '.$Desde.' , '.$this->Cant);
}
# --- Estructura
public function _Estructure($estructure){
$this->Estructura = $estructure;
}
# --- Devolucion
public function _Devolucion(){
$str = $this->Estructura;
while($Campo = $this->Mysql->Assoc($this->Consulta)){
foreach($Campo as $clave => $valor) {
}
echo $str;
}
}
# --- Navegacion
public function _Navegacion($botones){
# Vars
$this->Botones = $botones;
if(($this->Botones)>=3){
// next
if(($this->Posicion)>1 && ($this->Paginas)>1){
echo '<input type="button" onClick="Paginacion('.(($this-Posicion)-1).')" value="next">';
}
// numbers
for($i = 1;$i<$this->Botones;$i++){
if($i<$this->Paginas){
echo '<input type="button" value="'.$i.'" onClick="Paginacion('.$i.')">';
}
}
// prev
if(($this->Posicion)<($this->Paginas)){
echo '<input type="button" onClick="Paginacion('.(($this->Posicion)+1).')" value="prev">';
}
}
if(($this->Botones)<=2){
// next
if(($this->Posicion)>1 && ($this->Paginas)>1){
echo '<input type="button" onClick="Paginacion('.(($this->Posicion)-1).')" value="next">';
}
// prev
if(($this->Posicion)<($this->Paginas)){
echo '<input type="button" onClick="Paginacion('.(($this->Posicion)+1).')" value="prev">';
}
}
}
}
Su forma de uso:
Código PHP:
Ver original# --- Framework
include("../../Include/Cm_Framework.php");
# --- Posicion
if(isset($_POST['Page']) && $_POST['Page']==''){
$Posicion = intval($_POST['Page']);
}else{
$Posicion = 1;
}
# --- Configuracion
$Paginador = new Cm_Paginador;
$Paginador->_Mysql(new Cm_mysql,'Album',5,'DESC',1);
# --- Estructura
$Estructure = '<li><article class="Info"><h1><img src="Content/Albums/{Slug}/{Caratula}">{Titulo}</h1><p>{Pie}</p></article><article class="Multimedia" id="Album_{id}"><a href="http://Naylafernandez.com.ar/Album/{Slug}/" target="new" class="Ver" title="Ver Album"></a> <input type="button" title="Agregar Fotos" class="Agregar"> <input type="button" title="Editar Album" class="Editar"> <input type="button" title="Eliminar Album" class="Eliminar"></article></li>';
$Paginador->_Estructure($Estructure);
# --- Devolucion
$Paginador->_Devolucion();
# --- Paginacion
$Paginador->_Navegacion(5);
Lo que no funciona:
Código PHP:
Ver original$str = $this->Estructura;
while($Campo = $this->Mysql->Assoc($this->Consulta)){
foreach($Campo as $clave => $valor) {
}
echo $str;
}