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
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++;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.