I am creating a kind of portal with news which is divided and the container, which is where the news is stored and the last 3 are displayed. I have this code, which shows me from id 3 to 1 but I am looking for see only the last 3, can you explain?.
Next I show the code that I have:
home_container.php
<?php
include_once('includes/conectar.php');
$link=conectar();
?>
<div class="container">
<div class="row">
<?php
$total=mysqli_query($link,"SELECT MAX(id) FROM tbl_noticias_blog");
for($total=3; $total > 0 ; $total--){
$obtenertitulo=mysqli_query($link,"Select * from tbl_noticias_blog order By id='$total' DESC");
$titulo=mysqli_fetch_array($obtenertitulo);
$dc=mysqli_query($link,"Select * from tblnoticias_blog where titulo='$titulo[titulo]' Order By id DESC");
?>
<div class="col-md-4">
<h2>
<?php echo $titulo['titulo']; ?>
</h2>
<p>
<?php echo utf8_encode($titulo['descor']); ?>. </p>
<p><a class="btn btn-secondary" href="#" role="button">Ver detalles »</a></p>
</div>
<?php
}
?>
</div>
<hr>
</div>
With the Kevin query what the code shows is this:
Fixed as follows:
<?php
include_once('includes/conectar.php');
$link=conectar();
?>
<div class="container">
<div class="row">
<?php
$dc=mysqli_query($link,"Select * from tbl_noticias_blog where estatus='importante' Order By id DESC limit 3");
while($titulo=mysqli_fetch_array($dc)){
?>
<div class="col-md-4">
<h2>
<?php echo $titulo['titulo']; ?>
</h2>
<p>
<?php echo utf8_encode($titulo['descor']); ?>. </p>
<p><a class="btn btn-secondary" href="#" role="button">Ver detalles »</a></p>
</div>
<?php
}
?>
</div>
<hr>
</div>