This article is to share with you a non-refresh message board implemented by php combined with ajax. Let me take a look at it first. The final rendering:
The database connection code is as follows:
<?php $conn = @mysql_connect("localhost","root","root") or die ("MySql连接错误"); mysql_select_db("demo",$conn); mysql_query("set names 'utf8'"); ?>
The index.php file code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="bbs.css" type="text/css" rel="stylesheet"> <title>无刷新显示回帖</title> <script src="bbs.js" type="text/javascript"></script> </head> <body> <h1>无刷新显示回帖</h1> <div id="thread"> <?php include("conn.php"); $sql = "select * from `bbs_post` where `threadid` ='1' order by id asc"; $query =mysql_query($sql); while($row = mysql_fetch_array($query)){ ?> <div class="post" id="post<?php echo $row['id'];?>"> <div class="post_title"><?php echo $row['title'];?> [<?php echo $row['username'];?>]</div> <div class="post_content"><pre class="brush:php;toolbar:false"><?php echo $row['content'];?>
回帖 | |
姓名: | |
标题: | |
内容: | |