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 Link to comment https://forums.phpfreaks.com/topic/120426-solved-selecting-most-recent-articles/ 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++; } Link to comment https://forums.phpfreaks.com/topic/120426-solved-selecting-most-recent-articles/#findComment-620503 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 Link to comment https://forums.phpfreaks.com/topic/120426-solved-selecting-most-recent-articles/#findComment-620516 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 Link to comment https://forums.phpfreaks.com/topic/120426-solved-selecting-most-recent-articles/#findComment-620538 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.