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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.