Hello, i managed to understand how to generate divs from the numbers of row into an database. I can't figure out how to limit the amounth of items per pages just like in a normal ecommerce shop. You can navigate to page 1,2,3 etc. In my code it just spams each row into the page. I want 10 elements per page, then change page 2, then 3 etc.
I am newbie, i don't know even if i am doing this div generations corectly. And yes i know i have to use prepared statements for sql, but is easier to work with it like this.
This is the code i wrote:
$sql = "SELECT * from prodotti";
$result = $conn->query($sql);
for($x=0; $x<$result->num_rows;$x++){
$row = $result->fetch_assoc();
$id = $row["idprodotti"];
$nome = $row["nome"];
$descrizione = $row["descrizione"];
echo '<div class="container-prodotti">';
echo '<h1>'.$nome.'</h1>';
echo '<p>'.$descrizione.'</p>';
echo '</div>';
}
This is some code i made to know how many pages i need but idk how to go from here.
$nr_entrate = $result->num_rows; //29
$verifica_resto = $nr_entrate % 10;
$dividi_entrate = (int) ($nr_entrate / 10);
if($verifica_resto === 0){
$pagine = $dividi_entrate;
} else {
$pagine = $dividi_entrate + 1;
}