gaza165 Posted June 1, 2009 Share Posted June 1, 2009 Hello can someone tell me how i can get every single row in the database EXCEPT the last one... i need a query to bring everything back from the db but not the last row?? thanks <?php include ('dbconnect.php'); $message = mysql_query("SELECT * FROM chat"); while ($row = mysql_fetch_array($message)) { echo "<li><h2>".$row['nick'].": </h2><p class='word-wrap'>".$row['message']."</p></li>" ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160458-retrieving-all-but-last-row/ Share on other sites More sharing options...
kickstart Posted June 1, 2009 Share Posted June 1, 2009 Hi Using limit (although it is suggested on the Mysql site it is a bit of a bodge) <?php include ('dbconnect.php'); $message = mysql_query("SELECT * FROM chat ORDER BY MessageDate DESC LIMIT 1,18446744073709551615"); while ($row = mysql_fetch_array($message)) { echo "<li><h2>".$row['nick'].": </h2><p class='word-wrap'>".$row['message']."</p></li>" ; } ?> All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/160458-retrieving-all-but-last-row/#findComment-846754 Share on other sites More sharing options...
gaza165 Posted June 1, 2009 Author Share Posted June 1, 2009 Yeah thats not working to well, i am order my results from top down...so using ASC. for example... 1 2 3 4 5 6 7 8 9 10 ----->> delete this one $message = mysql_query("SELECT * FROM chat ORDER BY timestamp DESC LIMIT 1,18446744073709551615"); with ur code it deletes 1 not 10 anymore ideas??? Quote Link to comment https://forums.phpfreaks.com/topic/160458-retrieving-all-but-last-row/#findComment-846756 Share on other sites More sharing options...
kickstart Posted June 1, 2009 Share Posted June 1, 2009 Hi Even more of a nasty cheat then:- <?php include ('dbconnect.php'); $message = mysql_query("SELECT * FROM (SELECT * FROM chat ORDER BY MessageDate DESC LIMIT 1,18446744073709551615) ORDER BY MessageDate Asc"); while ($row = mysql_fetch_array($message)) { echo "<li><h2>".$row['nick'].": </h2><p class='word-wrap'>".$row['message']."</p></li>" ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/160458-retrieving-all-but-last-row/#findComment-846761 Share on other sites More sharing options...
gaza165 Posted June 1, 2009 Author Share Posted June 1, 2009 $message = mysql_query("SELECT * FROM (SELECT * FROM chat ORDER BY timestamp DESC LIMIT 1,18446744073709551615) ORDER BY timestamp ASC"); it says that the sql statement is not valid.... Quote Link to comment https://forums.phpfreaks.com/topic/160458-retrieving-all-but-last-row/#findComment-846767 Share on other sites More sharing options...
kickstart Posted June 1, 2009 Share Posted June 1, 2009 Hi Sorry, derived tables need an alias SELECT * FROM (SELECT * FROM chat ORDER BY timestamp DESC LIMIT 1,18446744073709551615) Deriv1 ORDER BY timestamp ASC All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/160458-retrieving-all-but-last-row/#findComment-846770 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.