Jump to content

Retrieving all but last row??


gaza165

Recommended Posts

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>" ;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/160458-retrieving-all-but-last-row/
Share on other sites

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

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???

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>" ;
}

?>

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.