2.3 ÏÔʾ·¢ÑÔcdisplay.php
±¾´úÂë¶ÎµÄÈÎÎñÊǽ«±íchatÖеÄÊý¾ÝÈ¡³ö£¬ÏÔʾÔÚÒ³¿òÖС£Ã¿´ÎË¢ÐÂʱ£¬È¡Êý¾Ý¿âÖÐ×î½üµÄ15Ìõ·¢ÑÔ¡£Í¬Ê±£¬Îª·ÀÖ¹Êý¾Ý¿âÎÞÏÞÔö´ó£¬ÐèÉè¼ÆÉ¾³ý³Â¾ÉÊý¾ÝµÄ¹¦ÄÜ¡£´úÂëÈçÏÂ
<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>
2.4 Ëͳö·¢ÑÔµ½Êý¾Ý¿âspeak.php
<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>
Íê³ÉÒÔÉϹ¤×÷ºó£¬Ò»¸ö¼òµ¥µÄÁÄÌìÊÒÖÆ×÷¾ÍÍê³ÉÁË¡£µ±È»£¬Éè¼ÆÕß¿ÉÒÔ¸ù¾Ý¸öÈ˰®ºÃ×öһЩ¸öÐÔ»¯Éè¼Æ£¬ÈçÔö¼ÓÒ»¸öÒ³¿ò£¬ÏÔʾµ±Ç°ÁÄÌìÊÒÈËÔ±Ãûµ¥¡¢Ôö¼Ó·¢ÑÔ±íÇ顢ȡµÃ·¢ÑÔÕßIP¡¢½øÒ»²½ÃÀ»¯Ò³ÃæµÈµÈ¡£

RSS¶©ÔÄ