Home >Backend Development >PHP Tutorial >my summer holiday English composition using PHP+MySql to write a chat room

my summer holiday English composition using PHP+MySql to write a chat room

WBOY
WBOYOriginal
2016-07-29 08:34:301228browse

Hello everyone! I haven’t seen you all for a long time. Last time I wrote about a chat room that uses PHP to operate through files. Of course it is full of loopholes, and every time I refresh the screen it is terrible! I have been thinking about it for a long time. Is there a way to get the speech information without refreshing? This effect can be achieved by using one more framework. That is, using one more framework is called getmsg. We let getmeg obtain information and ensure that the information obtained each time is the latest. That is, the speech obtained last time is not needed. Last time I edited The problem is that every time the information is obtained, it is repeated, which is not effective.
My design idea is: for every speech, submit it to the server, and then save it to a database. Getmsg will go to the server to obtain the latest speech data every few seconds, and ensure that the last speech obtained is not used. Removed it, and then superimposed the removed speech into a window (listmsg) dedicated to displaying speeches. In this way, we feel that the listmsg window will not have to be refreshed. Moreover, we can only see the speech information being added continuously, which has a very good effect.
How to add information from one frame to another frame? This idea can be realized using JavaScript:

Of course you have to create two tables in mysql, one table is used to save speech information, and one table is used to save several online ones. When listing the number of people online, we let it Refresh every 60 seconds, delete the speeches made one minute ago, and check whether a certain speaker has not spoken for a long time. If so, delete him.
Since the subsections of the table are very simple, in Don't write it out here, you will know it by looking at the program.This program works very well both online and offline!
表的名字是:chat和chat_getmsg

if(!isset($username))  
    $username="guest";
  $c
  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);
?>


Untitled Document


  
    
    
    
  
    
   n"; ?>
   n"; ?>
  

<body bgcolor="#FFFFFF"> <br></body>


if(!isset($username))
     $username="guest";
if(!isset($yanse))
      $yanse="blue";
if(!isset($objectname))
      $objectname="大家";
?>


Untitled Document




class="normalfont">
  
      
      
      
      
    
      
      
      
      
    
  
颜色:  
        
      
发言:  
        
         >
              
对象:
         >
      
回去





if(isset($username)&&isset($fayan)){
$c
mysql_select_db("database",$conid);
$sql="insert chat (username,objectname,action,msg,color) values ("$username","$objectname","NO","$fayan","$yanse")";
mysql_query($sql,$conid);
mysql_close($conid);
}
?>



Untitled Document

$c
mysql_select_db("database",$conid);
if(!isset($username))
     $username="getmsg";  
$dt=time();   
$newdate=date("YmdHis",$dt);
$fromdate=date("YmdHis",$dt-6);;
$sql="select username as name,msg,action,objectname ,shijian,color from chat where shijian>="$fromdate"";
$res=mysql_query($sql,$conid);
echo "n";
echo "n";
echo "n";
?>






Untitled Document

if(!isset($username))
$username="guest";
echo "n";
echo "n";
echo "n";
?>






Untitled Document







欢迎光临











Untitled Document





  在线人数



if(!isset($username))
    $username="guest";
$dt=time();   
$newdate=date("YmdHis",$dt);
$fromdate=date("YmdHis",$dt-200);
$linkid=mysql_connect("localhost","yourcount","password");
mysql_select_db("yourdatabase",$linkid);
$sql="update chat_getmsg set shijian="$newdate" where username="$username"";
mysql_query($sql,$linkid);
$sql="select username from chat_getmsg where shijian>="$fromdate"";
$res=mysql_query($sql,$linkid);  
while(list($username)=mysql_fetch_row($res)){
     echo "$username
n";
$fromdate=date("YmdHis",$dt-100);
$sql="delete from chat where shijian<="$fromdate"";
mysql_query($sql,$linkid);
mysql_close($linkid);
}
?>




【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】    

以上就介绍了my summer holiday英语作文 用PHP+MySql编写聊天室,包括了my summer holiday英语作文方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn