1
opa, Ai friends... well, the problem I’m having, I made a query to the database where I get all posts ordered by descending id, and just doesn’t work... it selects only the first.
follows the code
<?php
include 'connect.php';
$title = null;
$text = null;
$select = mysqli_query($con, "SELECT * FROM posts ORDER BY idp DESC");
// $conta = mysqli_num_rows($select);
if (mysqli_num_rows($select) <= 0) {
echo "<script>alert('Nao ha posts')</script>";
}else{
while ($in = mysqli_fetch_array($select)) {
$title = $in['titulo'];
$text = $in['texto'];
$id = $in['idp'];
}
}
?>
<div class="wrap-p">
<div id="title"><?php echo $title;?></div>
<div id="texto"><?php echo $text;?></div>
<div id="texto"><?php echo "$id";?></div>
</div>
</div><br><br>
<div class="wrap-p">
<div id="title"><?php echo $title;?></div>
<div id="texto"><?php echo $text;?></div>
<div id="texto"><?php echo "$id";?></div>
</div>
</div><br><br>
It seems your variables don’t list. Transform them into an array and add as the query brings a result, then do a for to render it in HTML.
– rogerdossantos
Hello @leandro, Welcome to Sopt, before you start make a visit to our [Tour].
– Icaro Martins