Home > Article > Backend Development > php+html implements chat room
1. The easiest way - keep refreshing the page
Database creation
create table chat ( chattime datetime, nick char(10), words char(150) );
login.php
<title>用户登录</title> <meta charset="utf-8"> 请输入您的昵称<br>
<title>显示用户发言</title> <meta http-equiv="refresh" c> <?php $conn = mysql_connect("127.0.0.1", "root", "7940175"); mysql_select_db("yuema", $conn); $str = "select * from chat order by chattime;"; $result = mysql_query($str, $conn); $rows = mysql_num_rows($result); mysql_data_seek($result, $rows-15); //取最近插入的15条数据 if ($rows<15) $l = $rows; else $l = 15; for ($i = 1; $i <= $l; $i++) { //输出这15条数据 list($chattime, $nick, $words) = mysql_fetch_row($result); echo $chattime; echo " ".$nick." "; echo $words; echo "<br>"; } ?>result display
2. Ajax acquisition, without refreshing the page
The above introduces the implementation of chat room with php+html, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.