gaza165 Posted June 15, 2009 Share Posted June 15, 2009 I am trying to run a query to fetch the last 10 records from a table... however $message = mysql_query("SELECT * FROM chat ORDER BY timestamp DESC LIMIT 0,10"); this brings back the first 10 not the last 10.... help!! Link to comment https://forums.phpfreaks.com/topic/162262-need-help-selecting-last-10-rows-from-database/ Share on other sites More sharing options...
Maq Posted June 15, 2009 Share Posted June 15, 2009 Take out the first '0' after your LIMIT clause. Link to comment https://forums.phpfreaks.com/topic/162262-need-help-selecting-last-10-rows-from-database/#findComment-856361 Share on other sites More sharing options...
gaza165 Posted June 15, 2009 Author Share Posted June 15, 2009 That still brings back the first 10.... i want the last 10.... 1 2 3 4 5 6 7 8 9 10 ----->> here onwards.... 12 13 14 15 16 17 18 19 20 Link to comment https://forums.phpfreaks.com/topic/162262-need-help-selecting-last-10-rows-from-database/#findComment-856363 Share on other sites More sharing options...
Maq Posted June 15, 2009 Share Posted June 15, 2009 Then take out DESC. Link to comment https://forums.phpfreaks.com/topic/162262-need-help-selecting-last-10-rows-from-database/#findComment-856364 Share on other sites More sharing options...
gaza165 Posted June 15, 2009 Author Share Posted June 15, 2009 $message = mysql_query("SELECT * FROM chat ORDER BY timestamp LIMIT 10"); Nope still brings back the first 10 records... Link to comment https://forums.phpfreaks.com/topic/162262-need-help-selecting-last-10-rows-from-database/#findComment-856366 Share on other sites More sharing options...
Maq Posted June 15, 2009 Share Posted June 15, 2009 $message = mysql_query("SELECT * FROM chat ORDER BY timestamp LIMIT 10"); Nope still brings back the first 10 records... ... SELECT * FROM chat ORDER BY timestamp DESC LIMIT 10 AND SELECT * FROM chat ORDER BY timestamp LIMIT 10 Should not both bring back the same first 10 records. Can I see a sample record from your table? Link to comment https://forums.phpfreaks.com/topic/162262-need-help-selecting-last-10-rows-from-database/#findComment-856380 Share on other sites More sharing options...
gaza165 Posted June 15, 2009 Author Share Posted June 15, 2009 Link to comment https://forums.phpfreaks.com/topic/162262-need-help-selecting-last-10-rows-from-database/#findComment-856417 Share on other sites More sharing options...
Maq Posted June 15, 2009 Share Posted June 15, 2009 I don't know what else to say, this should work: SELECT * FROM chat ORDER BY timestamp DESC LIMIT 10 You could try this, which should be just as reliable: SELECT * FROM chat ORDER BY id DESC LIMIT 10 Link to comment https://forums.phpfreaks.com/topic/162262-need-help-selecting-last-10-rows-from-database/#findComment-856432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.