You need only one query with LIMIT, example:
//this will select last 10 messages
$res=mysq_query('SELECT * FROM chat_messages ORDER BY addtime DESC LIMIT 10');


// this will print them from newer to older
while($message=mysql_fetch_array($res)) {
   echo $message['from'].': '.$message[message'].'<br>';
}

the connection is closed once your script is over (unless you use pconnect), you can not really find out the window has been closed.

you don't need to worry about any crash, sql server will take care of this

Michiel van Heusden wrote:

i'm working on a chat-app which has to be extremely plain and simple
mysql is available

i tried stripping some of the big scripts, but ended up in a mess
so i've ended up building a little app myself

i'm just wondering whether i'm using the right principe to get the data
refreshed in the chat..

i'm dropping all the messages as records in a mysql-table
then i have the php script

first printing all the html>>> stuff
opening a paragraph

and then a loop, querying the mysql, printing the data and querying again

is that a way to build this, or are there much better ways?

and some other questions:
* how can i make sure the db-connection is closed before the user closes the
window?
* is there any server-side problem with this (say, 100 people log on, and
are contineously querying mysql, won't there be some sort of crash?)

thanx a lot
michiel







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to