Jump to content


Photo

Chat Script limit mysql display?


  • Please log in to reply
2 replies to this topic

#1 AbydosGater

AbydosGater
  • Members
  • PipPipPip
  • Advanced Member
  • 435 posts
  • LocationAlways at computer!

Posted 30 October 2006 - 01:41 PM

Hi i have a basic chat script up and running, i got it done within an hour or so last night so its very basic at the moment.

But the section of my code that displays chat is..

$query = "SELECT * FROM chat_rc1 ORDER BY id DESC";
$result = mysql_query($query);
while($post = mysql_fetch_array($result)) {
$handle = $post['handle'];
$ip = $post['ip'];
$timestamp = $post['timestamp'];
$message = $post['message'];

echo "<i><b>$handle</b> @ $timestamp from $ip says:</i> <br> $message<br><br>";

}
echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"10; URL=recieve.php\">";

So it displays the posts, and then every 10 seconds the page refreshs.

As you can see there it displays the posts from the newest to oldest in the DESC.
But what i was wondering how would i use LIMIT to limit it to only display the last say 25 posts?
how could i do this?

Thanks
Abydos
www.abydosgaters.com

Current Project: Blog Application.. Undecided name.. Status: Coming along great.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 30 October 2006 - 01:43 PM

$query = "SELECT * FROM chat_rc1 ORDER BY id DESC LIMIT 25";

Ive got to ask though... is there any reason your using a database? Are you going to be keeping these chats? I meen, thats allot of work on the server for no reason otherwise.

#3 AbydosGater

AbydosGater
  • Members
  • PipPipPip
  • Advanced Member
  • 435 posts
  • LocationAlways at computer!

Posted 30 October 2006 - 01:44 PM

Great Thanks for the fast reply!
www.abydosgaters.com

Current Project: Blog Application.. Undecided name.. Status: Coming along great.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users