# PHP MySQL recent entry loop

**URL:** <https://forum.kirupa.com/t/php-mysql-recent-entry-loop/316288>\
**Category:** programming\
**Created:** [November 17, 2010, 7:44pm UTC](https://forum.kirupa.com/t/php-mysql-recent-entry-loop/316288 "2010-11-17T19:44:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spyderfx](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@spyderfx](https://forum.kirupa.com/u/spyderfx)\
**Post date:** [November 17, 2010, 7:44pm UTC](https://forum.kirupa.com/t/php-mysql-recent-entry-loop/316288/1 "2010-11-17T19:44:03Z")

</div>

Hi all,

I’m having a bit of trouble figuring out how to do this loop. I want to display in a table just the 5 most recent entries into the database. When I try to do this with a for or while loop it just spits out the first entry 5 times. What’s the best way to do this? Here is the code:

```auto

<?php

$db = mysql_select_db("serial");
$sql = "SELECT id, customer, product, motherboard, firmware, serial, warranty FROM entries ORDER BY id ASC";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$id = $row['id'];
$customer = $row['customer'];
$product = $row['product'];
$motherboard = $row['motherboard'];
$firmware = $row['firmware'];
$serial = $row['serial'];
$warranty = $row['warranty'];

while($i<5){
	echo "<tr>";
	echo "<td>" . $customer . "</td> <td>" . $product . "</td> <td>" . $motherboard . "</td> <td>" . $firmware . "</td> <td>" . $serial . "</td> <td>" . $warranty . "</td>";
	echo "</tr>";
	$i++;
	}
?>

Thanks

```
