I'm doing a pagination. So far so good, but when I'm on the homepage, it shows the results, everything ok. But when I click to go to the page 2
, it only changes the last result of the page.
example products.php
id 45,46,47,48,49
on this page everything is ok. But on page produtos.php?pagina=1
, it shows 46,47,48,49,50
.
session_start();
require '../conectaBanco.php';
$itens_pagina = 5;
if (isset($_GET['pagina'])) {
$pagina = $_GET['pagina'];
} else {
$pagina = 0;
}
$sql_code = "SELECT * FROM produtos LIMIT $pagina, $itens_pagina";
$execute = $conecta->query($sql_code) or die($$conecta->error);
$produto = $execute->fetch_assoc();
$num = $execute->num_rows;
$num_total = $conecta->query("SELECT * FROM produtos")->num_rows;
$num_paginas = ceil($num_total / $itens_pagina);