Latest rows
Moderator: General Moderators
Latest rows
Hi. Im making a simple news posting system, but im stuck on one thing. How would i make it display the latest 5 (or any other user specified number) posts from a database?
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
SELECT * FROM your_table_name ORDER BY `ID` DESC LIMIT 5- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
all fields of the row are returned from my query.. you can use [php_man]mysql_fetch_assoc[/php_man]() to retrieve each row in a while loop like so:
Code: Select all
<?php
$query = mysql_query('SELECT * FROM your_table_name ORDER BY `ID` DESC LIMIT 5') or die(mysql_error());
while($row = mysql_fetch_assoc($query))
{
print_r($row);
}
?>As described here: http://php.net/manual/en/function.mysql-fetch-array.php