復制代碼 代碼如下:
mysql> CREATE TABLE chat
-> (chtime DATATIME,
-> nick CHAR(10) NOT NULL,
->words CHAR(150));
復制代碼 代碼如下:
<html>
<head>
<title>用戶登錄</title>
</head>
<body>請輸入您的昵稱<br>
<form action=”main.php” method=”post” target=”_self”>
<input type=”text” name=”nick” cols=”20”>
<input type=”submit” value=”登錄”>
</body>
</html>
復制代碼 代碼如下:
<?
setcookie(“nick”,$nick) //用cookie記錄用戶昵稱,是常用的傳遞變量方法
?>
<html>
<title>山西鋁廠聊天室試用版ver1.0</title>
<frameset rows=”80%,*”>
<frame src=” cdisplay.php” name=”chatdisplay”>
<frame src=”speak.php” name=”speak”>
</frameset>
</html>
復制代碼 代碼如下:
<html>
<head>
<title>顯示用戶發言</title>
<meta http-equiv=”refresh” content=”5;url=cdisplay.php”>
</head>
<body>
<?
$link_ID=mysql_connect(“main”,”root”);
//鏈接Mysql服務器 服務器名為main,管理員名為root
mysql_select_db(“abc”); //選擇數據庫
$str=”select * from chat ORDER BY chtime;” ; //查詢字符串
$result=mysql_query($str, $link_ID); //送出查詢
$rows=mysql_num_rows($result); //取得查詢結果的記錄筆數
//取得最后15筆發言,并顯示
@mysql_data_seek($resut,$rows-15); //移動記錄指針到前15筆記錄
if ($rows<15) $l=$rows; else $l=15; //記錄總數小于15,則最多為該記錄數
for ($i=1;$i<=$l;$i++) {
list($chtime,$nick,$words)=mysql_fetch_row($result);
echo $chtime; echo “ “;echo $nick; echo”:” ; echo $words; echo “<BR>”;
}
//清除庫中過時的數據
@mysql_data_seek($result,$rows-20); //移動記錄指針到前20筆記錄
list($limtime)=mysql_fetch_row($result);
$str=”DELETE FROM chat WHERE chtime<'$limtime' ;” ;
$result=mysql_query($str,$link_ID); //送出查詢字符串,庫中只留前20個記錄
mysql_close($link_ID);
?>
</body>
</html>
復制代碼 代碼如下:
<html>
<head>
<title>發言</title>
</head>
<body>
<?
If ($words)
{ $link_ID=mysql_connect(“main”,”root”);
mysql_select_db(“abc”); //數據庫名為abc
$time=date(y).date(m).date(d).date(h).date(i).(date(s); //取得當前時間
$str=”INSERT INTO chat(chtime,nick,words) values
(‘$time','$nick','$words');” ;
mysql_query($str,$link_ID); //送出發言到數據庫
mysql_close($link_ID);
}
?>
//輸入發言的表單
<form action=”speak.php” method=”post” target=” _self”>
<input type=”text” name=”words” cols=”20”>
<input type=”submit” value=”發言”>
</form>
</body>
</html>
新聞熱點
疑難解答