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 ??? Quote Link to comment Share on other sites More sharing options...
btherl Posted July 29, 2008 Share Posted July 29, 2008 Can you show us your current code? Quote Link to comment 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>"; } Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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! 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.