1
I have a pagination in PHP and MYSQLI, and I would like the link of the pages below to be limited, for example:
Pages: 1 2 3 4 5 (goes up to 100), appear only the first 5, if I have on page 10, shows me 8 9 10 11 12, I do not know if you understand me, but what happens to me is that I have a lot of items added in the bank and what happens is that more than 200 pages appear, and I want to show the links of at least 5. Follow the code:
<?php
$pagina = (isset($_GET['pagina']))? $_GET['pagina'] : 1;
$banco = mysqli_query($conecta, "SELECT * FROM produtos WHERE empresa='1' AND ativo='1'");
$total = mysqli_num_rows($banco);
$registros = 10;
$numPaginas = ceil($total/$registros);
$inicio = ($registros*$pagina)-$registros;
$banco = mysqli_query($conecta, "SELECT * FROM produtos WHERE empresa='1' AND ativo='1' LIMIT $inicio,$registros");
$total = mysqli_num_rows($banco);
while($exibe_pecas = mysqli_fetch_array($banco)) {
?>
<div class="conteudo_p">
<div class="codigo_p"><?php echo $exibe_pecas['codigo']; ?></div>
<div class="nome_p"><?php echo $exibe_pecas['nome']; ?></div>
<div class="quantidade_p"><?php echo $exibe_pecas['qtde_estoque']; ?></div>
<div class="preco_p">R$ <?php echo $exibe_pecas['prc_venda']; ?></div>
<div class="acao_p">#</div>
</div>
<?php } ?>
<?php
if($pagina > 1) {
echo "<a href='index.php?pagina=".($pagina - 1)."' class='controle'>« anterior</a>";
}
for($i = 1; $i < $numPaginas; $i++) {
$ativo = ($i == $pagina) ? 'numativo' : '';
echo "<a href='index.php?pagina=".$i."' class='numero ".$ativo."'> ".$i." </a>";
}
if($pagina < $numPaginas) {
echo "<a href='index.php?pagina=".($pagina + 1)."' class='controle'>proximo »</a>";
}
?>