Pagination of mysqli for PDO

Asked

Viewed 21 times

2

Good afternoon, I’m trying to develop a page system for my tables, and already had a code in mysqli so I decided to take advantage, but I had to change to Pdo and it doesn’t work.

The code so far shows the correct page number depending on the number of users I have and also the variable $qnt_result_pg = 2; the problem is when clicking to switch page that nothing happens simply on the link of the site switches to the page I selected. //Specify the number of items per page $qnt_result_pg = 2;

//calcular o inicio visualização
$inicio = ($qnt_result_pg * $pagina) - $qnt_result_pg;

//paginação
$result_pg = "SELECT COUNT(username) AS num_result FROM utilizador";
$stm2 =$pdo->prepare($result_pg);
$stm2->execute();
$row_pg = $stm2->fetch(PDO::FETCH_ASSOC);
//Quantidade de pagina 
$quantidade_pg = ceil($row_pg['num_result'] / $qnt_result_pg);
//Limitar os link antes depois
$max_links = 10;
//mostrar paginação
echo "<div>";
echo "<a href='adminuti.php?pagina=1'>Primeira</a> ";

for($pag_ant = $pagina - $max_links; $pag_ant <= $pagina - 1; $pag_ant++){
if($pag_ant >= 1){
echo "<a href='adminuti.php?pagina=$pag_ant'>$pag_ant</a> ";
}
}

echo "<a><span style=color:orange> | $pagina | </span></a> ";

for($pag_dep = $pagina + 1; $pag_dep <= $pagina + $max_links; $pag_dep++){
if($pag_dep <= $quantidade_pg){
echo "<a href='adminuti.php?pagina=$pag_dep'>$pag_dep</a> ";
}
}
echo "<a href='adminuti.php?pagina=$quantidade_pg'>Ultima</a>";
echo "</div>";

Basically the changes I made were

   $result_pg = "SELECT COUNT(idp) AS num_result FROM partituras2";
   $resultado_pg = mysqli_query($ligaBD, $result_pg);
   $row_pg = mysqli_fetch_assoc($resultado_pg);

passed to

$result_pg = "SELECT COUNT(username) AS num_result FROM utilizador";
$stm2 =$pdo->prepare($result_pg);
$stm2->execute();
$row_pg = $stm2->fetch(PDO::FETCH_ASSOC);
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.