I am trying to display the top 5 newest itmes added to the database. I have it showing all of them on my items.php page, but I would like to put 5 on the dashboard.php page.
I am just learning php/mysql and have only been doing it for about 4 days and I feel I am learning pretty quick, but I cannot find this when doing a search.
Here is my code to get the full list of items.
<?php
$SQL_GetProducts = "SELECT * FROM `new_equip` ORDER BY `id` DESC;";
$R_GetProducts = mysql_query($SQL_GetProducts, $Link);
while ($row = mysql_fetch_assoc($R_GetProducts))
{
$eid = $row['id'];
$name = $row['name'];
$model = $row['model'];
$desc = $row['desc'];
$imagename = $row['image'];
$date = $row['date'];
if (!file_exists("../UImages/" . $imagename) || strlen($imagename) < 5)
{
$imagename = "NoImage.jpg";
}
?>
<tbody>
<tr>
<td>
<div class="thumbnail">
<div class="thumbnail-view">
<a href="../UImages/<?php echo $imagename; ?>" class="thumbnail-view-hover ui-lightbox"></a>
<img src="../UImages/<?php echo $imagename; ?>" width="125" alt="Gallery Image" />
</div>
</div> <!-- /.thumbnail -->
</td>
<td><?php echo $name; ?></td>
<td>
<p><?php echo wordwrap($desc, 90, "<br />");?> </p>
</td>
<td><?php echo $date; ?></td>
<td class="text-center">
<button class="btn btn-xs btn-primary"><i class="fa fa-pencil"></i></button>
<button class="btn btn-xs btn-secondary"><i class="fa fa-times"></i></button>
</td>
</tr>
<?php } ?>
</tbody>
From what I have read and seen I need to have something like this
$SQL_GetProducts = "SELECT * FROM `new_equip` ORDER BY `id` DESC LIMIT 0, 5";
Then I read something about a return $query->fetch();
Any help would be greatly appreciated.