gaza165 Posted June 1, 2009 Share Posted June 1, 2009 I have an SQL query that fetches all the entries in a database expect from the last one in the table...now i need to limit it to the last 10 records ordered by timestamp. can anyone help?? <?php include ('dbconnect.php'); $message = mysql_query("SELECT * FROM (SELECT * FROM chat ORDER BY timestamp DESC LIMIT 1,18446744073709551615) Deriv1 ORDER BY timestamp ASC "); while ($row = mysql_fetch_array($message)) { echo "<li><h2>".$row['nick'].": </h2><p class='word-wrap'>".$row['message']."</p></li>" ; } ?> Link to comment https://forums.phpfreaks.com/topic/160476-sql-limit/ Share on other sites More sharing options...
gaza165 Posted June 1, 2009 Author Share Posted June 1, 2009 help!! Link to comment https://forums.phpfreaks.com/topic/160476-sql-limit/#findComment-846859 Share on other sites More sharing options...
aschk Posted June 1, 2009 Share Posted June 1, 2009 Heh Gaz, not that bad is it? I'm not sure why you're trying to work from a derived table, considering you're just doing another SELECT on it. SQL query to fetch chat in last to 1st ordering. SELECT * FROM chat ORDER BY timestamp DESC SQL query to fetch chat; last 10 items starting from the 2nd to last SELECT * FROM chat ORDER BY timestamp DESC LIMIT 1,10 You might want to review how the LIMIT clause works (http://dev.mysql.com/doc/refman/5.1/en/select.html) Of course I might have totally missed the point of the question, or what you were really after. Link to comment https://forums.phpfreaks.com/topic/160476-sql-limit/#findComment-846892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.