本文就是和大家分享一款由php结合ajax实现的无刷新留言板,先给大家看一下最后的效果图:
数据库连接代码如下:
<?php $conn = @mysql_connect("localhost","root","root") or die ("MySql连接错误"); mysql_select_db("demo",$conn); mysql_query("set names 'utf8'"); ?>
index.php文件代码如下:
<!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'];?>
回帖 | |
姓名: | |
标题: | |
内容: | |