Jump to content

[SOLVED] Selecting most recent articles...


HFD

Recommended Posts

This may seem like a really dumb problem lol, but my minds gone blank. I want to select the last 3 entries in the database (The last entry is always the most recently added), and output them. Currently I'm using this:

 

while ($count <= 3)
{
$query = "SELECT tutid, title FROM tutorials ORDER BY tutid DESC";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
echo "$count: $title";
$count++;
}

 

But it isn't retrieving any records...Anyone got any idea what's wrong? Thanks

Link to comment
https://forums.phpfreaks.com/topic/120426-solved-selecting-most-recent-articles/
Share on other sites

ORDER BY tutid DESC LIMIT 0,3

 

0 means, start at first returned row

3 means, get three rows.

 

$query = "SELECT tutid, title FROM tutorials ORDER BY tutid DESC LIMIT 0,3";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$count = 0;
while (mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "$count: {$row['title']}";   // notice {} around array variable
$count++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.