我的设计思想是:每一次发言,都把它提交到服务器上,然后保存到一个数据库里,每格几秒钟getmsg就去服务器上取得 最新发言数据,并保证上次取得的发言就不要取下来了,然后把取下来的发言叠加到一个专门显示发言的窗口(listmsg)去。这样我们就感觉listmsg窗口不会有重刷新的感觉而且,只是看到发言信息不断加进去,这样就有很好的效果,
怎样在一个框架把信息加到另个框架去了?用JavaScript就可以实现这个想法的:
当然你得在mysql里建两个表,一个表用于保存发言信息,一个表用于保存几个在线的,在列在线人数时,我们让它每个60秒刷新一次,并把一分钟以前的发言删掉,并看某个发言人是不是很长时间没发言了,是的话,就删掉他,
由于表的子段很简单,在这里就不要写出来了,看程序就会知道了。这个程序在网上网下测试的效果都很好!
表的名字是:chat和chat_getmsg
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);
?>
if(!isset($username))
$username="guest";
if(!isset($yanse))
$yanse="blue";
if(!isset($objectname))
$objectname="大家";
?>
if(isset($username)&&isset($fayan)){
$conid=mysql_connect("localhost","yourcount","yourpassword");
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);
}
?>
$conid=mysql_pconnect("localhost","yourcount","password");
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";
?>
if(!isset($username))
$username="guest";
echo "n";
echo "n";
echo "n";
?>
欢迎光临
在线人数
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);
}
?>
【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】