Jump to content

[SOLVED] Help with displaying "second to last" ID sorted by most recent


theresa79

Recommended Posts

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

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.