Re: some help needed building chat-app
| From: | Marek Kilimajer | Date: | Thu, 06 Mar 2003 11:52:50 +0000 |
| Subject: | Re: some help needed building chat-app | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138448@lists.php.net to get a copy of this message | ||
You should understand the concept of php better. The browser request the page, php script prints the messages and closes the conection, the page is displayed. You cannot continue printing out after the conection is closed. So you need to tell the browser to refresh after certain amount of time to get a fresh copy with new messages.
Michiel van Heusden wrote:
actually it's not as much about refreshing the whole page it's just about refreshing the chat-messages that have been posted so i need some sort of loop that continually seeks for new data and if any, prints them thanks anyway ----- Original Message ----- From: "Marek Kilimajer" <kilimajer@webglobe.sk> To: "Michiel van Heusden" <michiel@aemulatio.nl> Cc: <php-general@lists.php.net> Sent: Thursday, March 06, 2003 11:00 AM Subject: Re: [PHP] some help needed building chat-appthisIf you mean making the client refresh the page after an amount of time,useheader('Refresh: 10'); it is in seconds Michiel van Heusden wrote:lookingthanks for your replies the other thing i was trying to ask :) is how to keep on looping andfor new messages is just a plain loop ok or should i use a timer or whatsoever, i have no clue right now it's a bit like $x = "loop"; do while ($x == "loop") { //mysql_query (select new messages) //output new messages to bottom of html } "Marek Kilimajer" <kilimajer@webglobe.sk> wrote in message news:3E661A97.7080104@webglobe.sk...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
againMichiel 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
closesis 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
andthewindow? * is there any server-side problem with this (say, 100 people log on,
are contineously querying mysql, won't there be some sort of crash?) thanx a lot michiel