
grunst3r
Beta
Verificado por Whatsapp
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Para lo que no saben que es CLASS de php ??'
Una clase no parece ser otra cosa que una especie de plantilla en la que se pueden definir una serie de variables -a las que se pueden asignar valores predefinidos- y funciones que pueden ser invocadas -en todo o en parte- desde cualquier otra parte del documento.
Esta paginacion les servira a muchos es un class que hace un año lo encontre y lo empese a estudiar los codes y pues tratando de mejorarlo mas, pero tambien ustedes pueden mejorarlo..
bueno para usar el que tengo pues puedes estar practicando lo primro que aremos sera crear un archivo llamado:
Pagination.class.php
Y bueno ya una vez de haber guardado el CLASS pues nos empesamos hacer el archivo donde lo queremos mostrar ...
En mi caso lo mostratrare en mi archivo:
Y por ultimo el style css para la paginacion esto lo puedes editar y darle el color que quieran para los que no saben esto lo ponen en su html donde saldra la paginacion.
Bueno pronto espare poniendo algunas modificaciones espero que ustedes tambien... xD
Una clase no parece ser otra cosa que una especie de plantilla en la que se pueden definir una serie de variables -a las que se pueden asignar valores predefinidos- y funciones que pueden ser invocadas -en todo o en parte- desde cualquier otra parte del documento.
Esta paginacion les servira a muchos es un class que hace un año lo encontre y lo empese a estudiar los codes y pues tratando de mejorarlo mas, pero tambien ustedes pueden mejorarlo..
bueno para usar el que tengo pues puedes estar practicando lo primro que aremos sera crear un archivo llamado:
Pagination.class.php
PHP:
<?php
/*******************************
Codigo copartido forobeta.com
*******************************/
class CSSPagination
{
private $totalrows;
private $rowsperpage;
private $website;
private $page;
private $sql;
public function __construct($sql, $rowsperpage, $website)
{
$this->sql = $sql;
$this->website = $website;
$this->rowsperpage = $rowsperpage;
}
public function setPage($page)
{
if (!$page) { $this->page=1; } else { $this->page = $page; }
}
public function getLimit()
{
return ($this->page - 1) * $this->rowsperpage;
}
private function getTotalRows()
{
$result = @mysql_query($this->sql) or die ("query failed!");
$this->totalrows = mysql_num_rows($result);
}
private function getLastPage()
{
return ceil($this->totalrows / $this->rowsperpage);
}
public function showPage()
{
$this->getTotalRows();
$pagination = "";
$lpm1 = $this->getLastPage() - 1;
$page = $this->page;
$prev = $this->page - 1;
$next = $this->page + 1;
$pagination .= "<div class=\"pagination\"";
if($margin || $padding)
{
$pagination .= " style=\"";
if($margin)
$pagination .= "margin: $margin;";
if($padding)
$pagination .= "padding: $padding;";
$pagination .= "\"";
}
$pagination .= ">";
if ($this->getLastPage() > 1)
{
if ($page > 1)
$pagination .= "<a href='$this->website?page=$prev' title='Anterior'>« Anterior</a>";
else
$pagination .= "<span class=\"disabled\">« Anterior</span>";
if ($this->getLastPage() < 9)
{
for ($counter = 1; $counter <= $this->getLastPage(); $counter++)
{
if ($counter == $page)
$pagination .= "<span class=\"current\">".$counter."</span>";
else
$pagination .= "<a href='$this->website?page=$counter' title='pagina $counter'>".$counter."</a>";
}
}
elseif($this->getLastPage() >= 9)
{
if($page < 4)
{
for ($counter = 1; $counter < 6; $counter++)
{
if ($counter == $page)
$pagination .= "<span class=\"current\">".$counter."</span>";
else
$pagination .= "<a href='$this->website?page=$counter' title='pagina $counter'>".$counter."</a>";
}
$pagination .= "...";
$pagination .= "<a href='$this->website?page=$lpm1' title='pagina $lpm1'>".$lpm1."</a>";
$pagination .= "<a href='$this->website?page=".$this->getLastPage()."' title='pagina ".$this->getLastPage()."'>".$this->getLastPage()."</a>";
}
elseif($this->getLastPage() - 3 > $page && $page > 1)
{
$pagination .= "<a href='$this->website?page=1' title='pagina 1'>1</a>";
$pagination .= "<a href='$this->website?page=2' title='pagina 2'>2</a>";
$pagination .= "...";
for ($counter = $page - 1; $counter <= $page + 1; $counter++)
{
if ($counter == $page)
$pagination .= "<span class=\"current\">".$counter."</span>";
else
$pagination .= "<a href='$this->website?page=$counter' title='pagina $counter'>".$counter."</a>";
}
$pagination .= "...";
$pagination .= "<a href='$this->website?page=$lpm1' title='pagina $lpm1'>$lpm1</a>";
$pagination .= "<a href='$this->website?page=".$this->getLastPage()."' title='pagina ".$this->getLastPage()."' >".$this->getLastPage()."</a>";
}
else
{
$pagination .= "<a href='$this->website?page=1' title='pagina 1'>1</a>";
$pagination .= "<a href='$this->website?page=2' title='pagina 2'>2</a>";
$pagination .= "...";
for ($counter = $this->getLastPage() - 4; $counter <= $this->getLastPage(); $counter++)
{
if ($counter == $page)
$pagination .= "<span class=\"current\">".$counter."</span>";
else
$pagination .= "<a href='$this->website?page=$counter' title='pagina $counter'>".$counter."</a>";
}
}
}
if ($page < $counter - 1)
$pagination .= "<a href='$this->website?page=$next' title='pagina $counter'>Siguiente »</a>";
else
$pagination .= "<span class=\"disabled\">Siguiente »</span>";
}
$pagination .= "</div>\n";
return $pagination;
}
}
?>
En mi caso lo mostratrare en mi archivo:
PHP:
<?php
require_once("Pagination.class.php");
$sql1 = "SELECT * FROM table WHERE whateverfilter ORDER BY id "; // Consulta para mostrar el total de resultados
$rowsperpage = 15; // mostrar la cantidad de resultados
//$website = "?id=1"; // url de la web para la indexacion esta parte falta mejorar xD
$pagination = new CSSPagination($sql1, $rowsperpage, $website); // Creando Objetivo
$pagination->setPage($_GET[page]); // la paginacion en GET xD
$sql2 = "SELECT * FROM table WHERE whateverfilter ORDER BY id LIMIT " . $pagination->getLimit() . ", " . $rowsperpage;
$result = @mysql_query($sql2, $any_connection_db) or die("<b> No hay Coneccion </b>");
while ($rows = mysql_fetch_array($result))
{
// Aqui el contenido o la lits a de de tu tabla
}
echo $pagination->showPage(); // HTML Css mostrar paginacion
?>
Y por ultimo el style css para la paginacion esto lo puedes editar y darle el color que quieran para los que no saben esto lo ponen en su html donde saldra la paginacion.
HTML:
<style>
div.pagination {
padding: 3px;
margin: 3px; font-family:Verdana; font-size:8pt; text-decoration:none
}
div.pagination a {
margin: 2px;
border: 1px solid #000000;
text-decoration: none; /* no underline */
color: #000000;font-family:Verdana; font-size:8pt; padding-left:5px; padding-right:5px; padding-top:2px; padding-bottom:2px
}
div.pagination a:hover, div.pagination a:active {
margin: 2px;
border: 1px solid #800000;
background-color: #800000;
color: #FFFFFF;font-family:Verdana; font-size:8pt; padding-left:5px; padding-right:5px; padding-top:2px; padding-bottom:2px; text-decoration:none
}
div.pagination span.current {
margin: 2px;
border: 1px solid #000000;
font-weight: bold;
background-color: #000000;
color: #FFFFFF;font-family:Verdana; font-size:8pt; padding-left:5px; padding-right:5px; padding-top:2px; padding-bottom:2px
}
div.pagination span.disabled {
margin: 2px;
border: 1px solid #999999;
color: #999999;font-family:Verdana; font-size:8pt; padding-left:5px; padding-right:5px; padding-top:2px; padding-bottom:2px
}
a:hover.list { font-family: Verdana; font-size: 8pt; font-variant: small-caps;
text-decoration: underline; text-transform: capitalize;
color: #006699; line-height: 200%; font-weight: bold }
a.list { text-transform: capitalize; font-variant: small-caps; font-family: Verdana;
font-size: 8pt; color: #FF0000; text-decoration: underline;
line-height: 200%; font-weight: bold }
</style>