Hello everyone! Long time no see everyone, the last time I wrote a file with PHP chat room operation, of course, is porous, and every time the screen is very bad! I think for a long time, is there a way not to refresh, you can get the message of the speech? The effect is achieved by using a single frame, that is to use a framework we call getmsg, we let getmeg to obtain information and ensure that every time the information is the latest, is the last to get the speech is not, the last I made up is every time to obtain information is repeated, so the effect is not good.
My idea of design is: every time I speak, it is submitted to the server, and then saved to a database, every few seconds getmsg to the server to obtain the latest data, and to ensure that the last statement was not taken down, and then put the statements taken down to a special display of the Statement of the window ( LISTMSG) go. So we feel that the Listmsg window will not have a heavy refresh feeling and, just to see the message added constantly, this will have a good effect,
How do you add information to another frame in one frame? The idea can be achieved with javascript:
<script language= "JavaScript" >
<!--
var win=parent.frames[0]//First frame that appears in the document for the first time <frame>
var doc=win.document//Get Document
Doc.write ("Speech information")//So you can add information to another frame!
-->
</script>
Of course, you have to build two tables in MySQL, a table for saving speech information, a table is used to save a few online, when the number of people on the line, we let it refresh every 60 seconds, and a minute before the statement deleted, and see if a speaker is not a long time did not speak, yes, then delete him,
Because the child sections of the table are very simple, do not write here, look at the program will know. This program in the network under the test results are very good!
The name of the table is: Chat and chat_getmsg
<!--main frame chat.php-->
? Php
if (!isset ($username))
$username = "Guest";
$conid =mysql_connect ("localhost", "yourcounter", "password");
mysql_select_db ("Yourdadabase", $conid);
$dstr =date ("Ymdhis");
$sql = "Insert Chat_getmsg (Username,shijian) VALUES (' $username ', ' $dstr ')";
mysql_query ($sql, $conid);
$sql = "Update chat_getmsg set shijian= ' $dstr ' where username= ' $username '";
mysql_query ($sql, $conid);
Mysql_close ($conid);
?>
<title>untitled document</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<frameset rows= "283,105" frameborder= "YES" border= "1" framespacing= "0" cols= "*" >
<frameset cols= "520,113" frameborder= "yes" border= "1" framespacing= "0" rows= "*" >
<frame name= "Topframe" scrolling= "Auto" border= "1" noresize src= "list.html" >
<frame name= "Rightframe" scrolling= "Auto" border= "1" noresize src= "username.php" >
</frameset>
<frameset rows= "17,90" frameborder= "yes" border= "1" framespacing= "0" cols= "*" >
? PHP echo "<frame name=" topFrame1 "scrolling=" NO "border=" 1 "noresize src=" getmsg1.php?username= $username ">n";? >
? PHP echo "<frame name=" BottomFrame "scrolling=" NO "border=" 1 "noresize src=" fayan.php?username= $username ">n";? >
</frameset>
</frameset>
<noframes><body bgcolor= "#FFFFFF" >
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.