Pagination of products with PDO

Asked

Viewed 276 times

-1

I need to create a pagination for my database with 180 products, only the images without pagination appear all 180 side by side, as I can do to limit the images 10 per page side by side?

Here is my code:

<?php
echo'<table width="88%" height="10" cellspacing="0" cellpadding="0"><tr>';
$conn = new PDO("mysql:host=localhost;dbname=loja", "root", "");
$stmt = $conn->prepare("SELECT * FROM `produtos` ORDER BY `id` ASC ");
$stmt->execute( );
$linha = $stmt->fetch(PDO::FETCH_ASSOC);
while($linha = $stmt->fetch(PDO::FETCH_ASSOC)) {
    echo'<br>';
    echo'<p><td align=center ><h2><font size="5" face="Trebuchet MS">'.$linha['nome'].'</font></font></p></h2>';
    echo "<div align=center ><img src='".$linha['foto']."' width='160' height='160' border='0'></p>";
    echo '<a href="carrinho.php?acao=add&id='.$linha['id'].'"><button type="button" name="" value="" class="quero">Eu Quero!</button>';
}
echo "</tr></table>";
?>

1 answer

0

To limit the amount of records of a query, use the clause LIMIT.

SELECT * FROM `produtos` ORDER BY `id` ASC LIMIT 10
  • because I would like to create a pagination with the links to the previous and next type page.

  • Read the link that rray commented on your question.

  • I’ll test here rray, vlw by the help.

  • I appreciate the help I got! Thank you very much!

Browser other questions tagged

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