Skip to content

Instantly share code, notes, and snippets.

@julioprotzek
Created January 4, 2011 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julioprotzek/764210 to your computer and use it in GitHub Desktop.
Save julioprotzek/764210 to your computer and use it in GitHub Desktop.
<div id="paginador">
<?php
include 'conexao/conexao.php';
$criterio = "";
if ($_GET["criterio"]!=""){
$txt_criterio = $_GET["criterio"];
$criterio = " where noticia like '%" . $txt_criterio . "%'";
}
$con = mysql_connect($host,$user,$pass,$banco);
mysql_select_db($banco);
$TAMANHO_PAGINA = 5;
$pagina = $_GET["pagina"];
if (!$pagina) {
$inicio = 0;
$pagina=1;
}
else {
$inicio = ($pagina - 1) * $TAMANHO_PAGINA;
}
$sql = "SELECT * FROM noticia ORDER BY id_noticia DESC";
$result = @mysql_query($sql,$con);
mysql_num_rows($result);
$total_paginas= $result / $TAMANHO_PAGINA;
$ssql = "select * from noticia " . $criterio . " limit " . $inicio . "," . $TAMANHO_PAGINA;
$rs = @mysql_query($ssql,$con);
while ($fila = mysql_fetch_object($rs)){
echo $fila->noticia;
}
mysql_free_result($rs);
mysql_close($con);
if ($total_paginas> 1){
for ($i=1;$i<=$total_paginas;$i++){
if ($pagina == $i)
//se mostro o índice da página atual, não coloco link
echo $pagina . " ";
else
//se o índice não corresponde com a página mostrada atualmente, coloco o link para ir a essa página
echo "<a href='index.php?p=noticia&pagina=" . $i . "&criterio=" . $txt_criterio . "'>". $i . "</a> ";
}
}
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment