首页 >后端开发 >php教程 >php+ajax制作无刷新留言板_PHP

php+ajax制作无刷新留言板_PHP

WBOY
WBOY原创
2016-05-29 11:48:37880浏览

本文就是和大家分享一款由php结合ajax实现的无刷新留言板,先给大家看一下最后的效果图:

数据库连接代码如下:

<&#63;php
$conn = @mysql_connect("localhost","root","root") or die ("MySql连接错误");
mysql_select_db("demo",$conn);
mysql_query("set names 'utf8'");
&#63;>

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">
<&#63;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)){ 
&#63;>
  <div class="post" id="post<&#63;php echo $row['id'];&#63;>">
        <div class="post_title"><&#63;php echo $row['title'];&#63;> [<&#63;php echo $row['username'];&#63;>]</div>
        <div class="post_content"><pre class="brush:php;toolbar:false"><&#63;php echo $row['content'];&#63;>

回帖
姓名:
标题:
内容:
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn