Quantcast
Channel: Últimos conteúdos
Viewing all articles
Browse latest Browse all 14190

Paginação

$
0
0
bom dia, estou com problema na paginação, ela está mostrando todas as paginas exemplo:

123456789101112

eu queria que mostra-se 1234 ai a pessoa clica-se no 4 ai mostra 5678 e assim vai.. como faço isso?

codigo abaixo:
 <?php
$pagina = $_GET['pag'];
if(!$pagina){
  $pagina = 1;
}
// Defina aqui a quantidade de resultados a serem exibidos em cada página
$limite = 5;	

// FAÇA UMA BUSCA SIMPLES NA SUA TABELA
if(empty($_GET["categoria"])){
	$cont = mysql_query("SELECT * FROM anuncios");
}else{
	$cont = mysql_query("SELECT * FROM anuncios WHERE categoria = '".strip_tags($_GET["categoria"])."'");

}
$total_registros = mysql_num_rows($cont); // Aqui você conta o total de registros da tabela
$total_paginas = ceil($total_registros / $limite); // Aqui divide o total de registros pelo limite de registros a serem exibidos para obter o total de páginas a serem exibidas



//Abaixo você vai fazer a equação que deverá 
$inicio = ($pagina * $limite) - $limite;


// AQUI VAI O SEU CÓDIGO
if(@$_POST){
			$sql = mysql_query("SELECT * FROM anuncios WHERE descricao LIKE '%".$_POST["query"]."%' ORDER BY ID DESC LIMIT $inicio,$limite");
	}else{
 
		if(empty($_GET["categoria"])){
			$sql = mysql_query("SELECT * FROM anuncios WHERE status = 'Ativo' AND ID ORDER BY RAND() LIMIT $inicio,$limite");
		}else{
			$sql = mysql_query("SELECT * FROM anuncios WHERE categoria = '".strip_tags($_GET["categoria"])."' AND status = 'Ativo' ORDER BY nome ASC LIMIT $inicio,$limite");
		}
	}
	
			if(mysql_num_rows($sql) == false){
				echo '<div align="center"><br /><strong>Nenhum anúncio encontrado.</strong><br /></div>';
				
			}else{
				
				while($ln = mysql_fetch_object($sql)){
					
	?>

<table width="100%" height="50" border="0">
        <tr>
          <td width="2%" height="110" align="center" valign="middle"><a href="javascript: ver_anuncio(<?php echo $ln->ID; ?>);" style="text-decoration:none;"><img style="border:3px solid #CCC;" src="uploads/<?php echo $ln->thumb; ?>" width="140" height="90" /></a></td>
          <td width="98%" align="left" valign="top">
          <div align="left" style="margin:5px; color:#333; font-size:11px;">Nome da Empresa: <strong style="text-transform:uppercase;"><?php echo $ln->empresa; ?></strong></div>
          <div align="left" style="margin:5px; color:#333; font-size:11px;">Telefone1: <strong><?php echo $ln->telefone; ?></strong>  Tel-2/Celular:<strong><?php echo $ln->telefone2; ?></strong> </div>
            <div align="left" style="margin:5px; color:#333; font-size:11px;">Cidade: <strong><?php echo $ln->cidade; ?></strong></div>
             <div align="left" style="margin:5px; color:#333; font-size:11px;"><?php echo truncate(strip_tags($ln->descricao), 100); ?>...</div>
            <div align="left" style="margin-left:5px; margin-top:10px;"><a href="javascript: ver_anuncio(<?php echo $ln->ID; ?>);" class=" anuncio" style="text-decoration:none;">Ver anúncio</a></div>
          </td>
        </tr>
      </table></p>
      
      <?php
			}
			?>
      <?php
				}
				?>
                
               <?php // Abaixo, um loop para exibir o link para as próximas páginas
for($i=1; $i <= $total_paginas; $i++)
{
    echo "<a href='index.php?pag=$i'>".$i."</a> ";
}

echo "<hr width='100%'>"."Você está atualmente na página: ".$pagina."<hr width='100%'>";
?>

    </td>

Viewing all articles
Browse latest Browse all 14190