自己总结了些屁经验
1.用ajax post数据到后台页面后,接着要重新连接数据库,别以为用之前的session连接过就可以了
2.为了处理返回乱码的问题,我添加了header("Content-Type:text/html;charset=GB2312");就可以正常显示了,后来在firefox下检验,却提示我下载这个网页,上网搜了不少资料,得到一个模糊的认识就是网页代码有语法错误,firefox为了安全起见不会直接显示而是提示下载,我重新检查了刚才那条语句,发现自己多写了个“\”,把它去掉后问题就解决了,哈哈,所以遇到这样的问题,好好检查一下html tag吧,毕竟firefox可不像ie那样smart
3.最后说一句,做web site的开发者,要负责任,别以为在ie下测试通过就万事大吉,毕竟不是所有人都用ie,还得要在别的浏览器下多做测试,这样才显示出你的专业水准
ajax脚本:
复制代码 代码如下:
<script> <BR>function viewpage(p){ <BR>if(window.XMLHttpRequest){ <BR>var xmlReq = new XMLHttpRequest(); <BR>} else if(window.ActiveXObject) { <BR>var xmlReq = new ActiveXObject('Microsoft.XMLHTTP'); <BR>} <BR>var formData = "page="+p; <BR>xmlReq.onreadystatechange = function(){ <BR>if(xmlReq.readyState == 4){ <BR>document.getElementById('content2').innerHTML = xmlReq.responseText; <BR>} <BR>} <BR>xmlReq.open("post", "hotel_list.php", true); <BR>xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); <BR>xmlReq.send(formData); <BR>return false; <BR>} <BR></script>
调用:
复制代码 代码如下:
header("Content-Type:text/html;charset=GB2312");
$pagesize=10;
//echo $_POST['page'];
$result = mysql_query("Select count(DISTINCT hotelname) FROM ".TBL_HOTELS);
$myrow = mysql_fetch_array($result);
$numrows=$myrow[0];
$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
if (isset($_POST['page'])){
$page=intval($_POST['page']);
}
else{
//设置为第一页
$page=1;
}
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
//计算记录偏移量
$offset=$pagesize*($page - 1);
//读取指定记录数
$result=mysql_query("select `hotelname` , count( * ) from ".TBL_HOTELS." GROUP BY `hotelname` order by id desc limit $offset,$pagesize");
$num = mysql_num_rows($result);
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
$hotelname[] = $row[0];
$countpeople[] = $row[1];
}
for($a=0;$a{
//$result=mysql_query("select count(title) from " . TBL_Comments ." where `title`=\"".$title[$a]."\"");
//$row = mysql_fetch_row($result);
echo "
\n";
echo "\n";
echo "\n";
echo "\n"; //rating_bar($title[$a],5); echo " | \n";
echo "
$hotelname[$a]\n"; echo " |
\n";
echo " \n";
echo " | \n";
echo "\n"; echo " 推荐人数:($countpeople[$a]) |\n"; echo "平均分: (".$count."票) | 评论数:()\n"; echo " |
\n";
}
echo "
echo "border=0>";
echo ""; echo "
|
";
http://www.bkjia.com/PHPjc/318828.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/318828.htmlTechArticle自己总结了些屁经验 1.用ajaxpost数据到后台页面后,接着要重新连接数据库,别以为用之前的session连接过就可以了 2.为了处理返回乱码的问...