Jump to content

echo second most recent id


dachshund

Recommended Posts

Hey,

 

I'm trying to echo only the second most recent id, but I can't get it to work, think I'm almost there.

 

any help?

 

here's what i've got

 

 


$sql="SELECT DISTINCT e.* FROM content e, content k WHERE `section` LIKE '%feature%' AND e.id < k.id ORDER BY id DESC LIMIT 1";
$result=mysql_query($sql);

 

Link to comment
https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/
Share on other sites

I'd say try this:

 

$sql="SELECT DISTINCT e.* FROM content e WHERE `section` LIKE '%feature%' ORDER BY id DESC LIMIT 1,1"

 

The first parameter is the starting (rows start at 0, not 1).  The second parameter is for how long you want to limit.  Here you just need one entry.

 

On a sidenote, does e.* signify table e, all columns?  I was trying to figure out why you're choosing all columns from table e when you have FROM content e (and is 'content e' valid, with a space?).  Well,  now I know that * is a wildcard char in google.

yeah that was from another page,

 

it can actually just be

 

$sql="SELECT * FROM content WHERE `section` LIKE '%feature%' ORDER BY id DESC LIMIT 2,1";

 

only the LIMIT 2,1"; part doesn't work, when I have LIMIT 1 that works fine, only obviously it's not the second to last.

 

it must be to do with the fact that the second to last entry doesn't have the section as 'feature', anyway to select the second to last one that does have 'feature'?

 

 

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.