dachshund Posted July 29, 2009 Share Posted July 29, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/ Share on other sites More sharing options...
onedumbcoder Posted July 29, 2009 Share Posted July 29, 2009 $sql="SELECT DISTINCT e.* FROM content e WHERE `section` LIKE '%feature%' ORDER BY id DESC LIMIT 2,1"; Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/#findComment-886009 Share on other sites More sharing options...
dachshund Posted July 29, 2009 Author Share Posted July 29, 2009 still doesn't work, the page appears blank. Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/#findComment-886030 Share on other sites More sharing options...
dachshund Posted July 29, 2009 Author Share Posted July 29, 2009 any bodyyyyy? Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/#findComment-886353 Share on other sites More sharing options...
BLaZuRE Posted July 30, 2009 Share Posted July 30, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/#findComment-886570 Share on other sites More sharing options...
dachshund Posted July 30, 2009 Author Share Posted July 30, 2009 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'? Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/#findComment-886650 Share on other sites More sharing options...
fenway Posted August 3, 2009 Share Posted August 3, 2009 You can't do "second to last" -- but you can do second -- so just flip the order clause around. Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/#findComment-889959 Share on other sites More sharing options...
dachshund Posted August 7, 2009 Author Share Posted August 7, 2009 Ah, how do I change the order clause? Make it ASC? Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/#findComment-892891 Share on other sites More sharing options...
fenway Posted August 10, 2009 Share Posted August 10, 2009 Ah, how do I change the order clause? Make it ASC? Yup... then just skip the first record. Quote Link to comment https://forums.phpfreaks.com/topic/167982-echo-second-most-recent-id/#findComment-894772 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.