<?php require_once('config.php'); ?> <?php if($words){ $query="insert into chat(chtime,nick,words,face)values(now(),'$nick','$words','$face')";//插入SQL语句 mysql_query($query,$link_ID); //发送留言到数据库 header("refresh:0; URL='https://www.jb51.net/show.php'"); } ?> <html> <head> <title>简单的php+mysql聊天室--显示留言页</title> <link href="https://www.jb51.net/style.css" type="text/css" /> <meta http-equiv="refresh" content="5;url=https://www.jb51.net/show.php"> </head> <body> <?php //最新发言显示在最下面 $sql="select * from chat order by chtime asc"; $result=mysql_query($sql); $total=mysql_num_rows($result); $info=($total/15-1)*15; if($total<15){ $str="select * from chat order by chtime asc;" ; //查询字符串 }else{ $str="select * from chat order by chtime asc limit $info,15;" ; //查询字符串 } $result=mysql_query($str,$link_ID); //送出查询 while($row=mysql_fetch_array($result)){ ?> <table cellpadding="5" cellspacing="1" bgcolor="#CBB486"> <tr> <td bgcolor="#F5E6C1">昵称:</td> <td bgcolor="#F5E6C1"><?php if($row[nick] == ""){echo "游客";}else{echo $row[nick];}?></td> <td bgcolor="#F5E6C1"><img src="face/PIC<?php echo $row[face];?>.GIF"></td> <td bgcolor="#F5E6C1">发言内容:</td> <td bgcolor="#F5E6C1"><?php echo $row[words];?></td> <td bgcolor="#F5E6C1">发言时间:</td> <td bgcolor="#F5E6C1"><?php echo $row[chtime];?></td> </tr> </table> <table cellpadding="0" cellspacing="0"> <tr> <td></td> </tr> </table> <?php } ?> </body> </html>
完整实例代码点击此处本站下载。