theresa79 Posted April 14, 2007 Share Posted April 14, 2007 Hi, For my blog, I am trying to figure out how I can retrieve and display only my second to last ID (blog entry), and then a separate page that displays only my third to last ID, etc., displayed by most recent date. I figured out how to display my first most recent, but can't seem to get the others without displaying everything up to most recent. I know I can always display a permalink but I need this for my front page that has different boxes for the 3 most recent and they all cannot happen in the same display because I will be creating snippets followed by images Here is what I have for getting the most recent: $sql = "SELECT * FROM eggblog_articles WHERE flag='1' ORDER BY date DESC LIMIT 1; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $date = date("D jS F Y",$row['date']); $time = date("g:i a",$row['date']); Thanks in advance Link to comment https://forums.phpfreaks.com/topic/46998-solved-help-with-displaying-second-to-last-id-sorted-by-most-recent/ Share on other sites More sharing options...
Glyde Posted April 14, 2007 Share Posted April 14, 2007 <?php // Get the second most recent $sql = "SELECT * FROM eggblog_articles WHERE flag='1' ORDER BY date DESC LIMIT 1,1"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { $date = date("D jS F Y",$row['date']); $time = date("g:i a",$row['date']); } ?> Use the 'offset' parameter of the LIMIT clause. [LIMIT {[offset,] row_count | row_count OFFSET offset}]. As posted above, change the LIMIT 1 in your query to LIMIT 1,1 which will indicate MySQL should start at the first offset. Link to comment https://forums.phpfreaks.com/topic/46998-solved-help-with-displaying-second-to-last-id-sorted-by-most-recent/#findComment-229184 Share on other sites More sharing options...
theresa79 Posted April 14, 2007 Author Share Posted April 14, 2007 Thanks so much for your rapid response! so how would it look if I wanted to display my third most recent entry only? Link to comment https://forums.phpfreaks.com/topic/46998-solved-help-with-displaying-second-to-last-id-sorted-by-most-recent/#findComment-229186 Share on other sites More sharing options...
Glyde Posted April 14, 2007 Share Posted April 14, 2007 SELECT * FROM eggblog_articles WHERE flag='1' ORDER BY date DESC LIMIT 2,1 Link to comment https://forums.phpfreaks.com/topic/46998-solved-help-with-displaying-second-to-last-id-sorted-by-most-recent/#findComment-229189 Share on other sites More sharing options...
theresa79 Posted April 14, 2007 Author Share Posted April 14, 2007 thank you. Link to comment https://forums.phpfreaks.com/topic/46998-solved-help-with-displaying-second-to-last-id-sorted-by-most-recent/#findComment-229191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.