chordsoflife Posted July 29, 2008 Share Posted July 29, 2008 I'm having trouble figuring out how to output only the latest three records. I have it in the order I want, and I'm thinking what I'm looking for is a do while loop, but how would I write something like that? How can I store the primary key in a variable during the loop to use it in the while? Wrong approach? Any help.. please ??? Link to comment https://forums.phpfreaks.com/topic/117104-solved-output-latest-three-records/ Share on other sites More sharing options...
btherl Posted July 29, 2008 Share Posted July 29, 2008 Can you show us your current code? Link to comment https://forums.phpfreaks.com/topic/117104-solved-output-latest-three-records/#findComment-602360 Share on other sites More sharing options...
chordsoflife Posted July 29, 2008 Author Share Posted July 29, 2008 Sure thing: $sql = "SELECT * FROM updates ORDER BY update_id DESC;"; $sql_result = mysql_query($sql,$connect) or die(mysql_error()); while ($row = mysql_fetch_array($sql_result)) { extract($row); echo "<div id=\"containerPost\"> <h1>" . $update_title . "</h1> <h2>Posted on " . $update_date . "</h2> <p>" . $update_content . "</p> </div>"; } Link to comment https://forums.phpfreaks.com/topic/117104-solved-output-latest-three-records/#findComment-602365 Share on other sites More sharing options...
corbin Posted July 29, 2008 Share Posted July 29, 2008 http://php.about.com/od/mysqlcommands/g/Limit_sql.htm Link to comment https://forums.phpfreaks.com/topic/117104-solved-output-latest-three-records/#findComment-602367 Share on other sites More sharing options...
secoxxx Posted July 29, 2008 Share Posted July 29, 2008 SELECT * FROM updates ORDER BY update_id DESC LIMIT 0,3 For the last 3 records in the db Link to comment https://forums.phpfreaks.com/topic/117104-solved-output-latest-three-records/#findComment-602368 Share on other sites More sharing options...
chordsoflife Posted July 29, 2008 Author Share Posted July 29, 2008 Wow, this stuff is just so much easier than I expected Thanks, guys! Link to comment https://forums.phpfreaks.com/topic/117104-solved-output-latest-three-records/#findComment-602685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.