1
I made the pagination available in the code below, following an example here of the stack, but it does not work as I need it to be: display at most 5 records per page and create the other pages. This code counts all the records of the table, let’s say it is 8, from that creates 8 pages and 8 blocks of pages, and would fit 5 in one and 3 in another. I accept suggestions on how to adjust.
$page = (isset($_GET['pagina'])) ? (int)$_GET['pagina'] : 1;
$limit = 5;
$offset = ($page * $limit) - $limit;
$sql = "SELECT * FROM registros LIMIT $limit OFFSET $offset";
$resp = mysqli_query($conexao, $sql);
$res = mysqli_fetch_assoc($resp);
$sql2 = "SELECT count(*) as count FROM registros";
$resultado = mysqli_query($conexao, $sql2);
$row = mysqli_fetch_assoc($resultado);
$total_de_paginas = $row['count'];
echo '<div>
<ul class="pagination pagination-sm pull-right">
<li><a href="#" id="anterior"><<</a></li>';
for($i = 1; $i <= $total_de_paginas; $i++){ ?>
<li><a href="?<?php echo http_build_query(array('page' => $i)) ?>"><?php echo $i ?></a></li>
<?php }
echo '<li><a href="#" id="próxima">>></a></li>
</ul>
</div> ';
I don’t know if that’s it, but there’s an error on line 3, the variable name is missing a letter at the end and the ";"
– Diego Keller