HFD Posted August 19, 2008 Share Posted August 19, 2008 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 Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 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++; } Quote Link to comment Share on other sites More sharing options...
HFD Posted August 19, 2008 Author Share Posted August 19, 2008 I've implemented the code, I had to change mysql_fetch_array to $row = mysql_fetch_array. Thanks for your help Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 19, 2008 Share Posted August 19, 2008 Was just checking if you're paying attention Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.