php中的分页跳转函数,点击时没反应
显示页面:
<html>
<head>
<title>Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript">
var xmlHttp ;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP") ;
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest() ;
}
}
function viewpage(p){
var formdata="page"+p ;
createXMLHttpRequest() ;
xmlHttp.onreadystatechange=callback ;
xmlHttp.open("POST" , "recordsend.php" , true) ;
xmlHttp.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded") ;
xmlHttp.send(formdata) ;
//return false ; //why?
}
function callback(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
document.getElementById("content").innerHTML=xmlHttp.responseText ;
}
}
}
</script>
</head>
<?php
session_start() ;
error_reporting(E_ALL & ~E_NOTICE);
?>
<body onLoad="viewpage(2)">
<h2 align="center">
<?php
echo $_SESSION["name"]."的聊天记录" ;
?>
</h2>
<div id="content"></div>
</body>
</html>
数据发送页面:recordsend.php
<?php
session_start() ;
error_reporting(E_ALL & ~E_NOTICE);
header("Content-Type:text/html ; charset=gb2312") ;
$pagesize=5 ;
$id=$_SESSION["id"] ;
include_once("conn.php") ;
$result=mysql_query("select count(DISTINCT id) from chatcontent where user_id='$id'") ;
$myrow=mysql_fetch_array($result) ;
$numrows=$myrow[0] ;
//获取总页数
if($numrows<$pagesize){
$pages=1 ;
}
if($numrows%$pagesize){
$pages=intval($numrows/$pagesize)+1 ;
}
else{
$pages=intval($numrows/$pagesize) ;
}
//获取页数
if(isset($_POST["page"])){
$page=intval($_POST["page"]) ;
}
else{
$page=1 ;
}
$first=1 ;
$sql="select * from chatcontent where user_id=".$id." order by id desc limit ".($pagesize*($page-1))." , $pagesize" ;
$zwt=mysql_query($sql) ;
$num=mysql_num_rows($zwt) ;
while($row=mysql_fetch_array($zwt , MYSQL_NUM)){
$content[]=$row[2] ;
$date[]=$row[3] ;
}
echo "<table cellspacing='0' cellpadding='0' border='1' align='center'>" ;
echo "<th>聊天内容</th><th>聊天时间</th>" ;
for($a=0 ; $a<$num ; $a++){
echo "<tr>" ;
echo "<td>".$content[$a]."</td>" ;
echo "<td>".$date[$a]."</td>" ;
echo "</tr>" ;
}
echo "</table>" ;
echo "<table cellspacing='0' cellpadding='0' border='0' align='center'>" ;
echo "<tr><td colspan='2'>" ;
echo "<span align='center'><font color='red'>第".$page."页/总共".$pages."页 | 总".$numrows."条记录 </font>" ;
if($page==1){
echo "首页|上一页|" ;
}
else{
echo "<a href='#' onclick=viewpage(".$first.")>首页</a>|" ;
echo "<a href='#' onclick=viewpage(".($page-1).")>上一页</a>|" ;
}
if($page==$pages){
echo "下一页|尾页" ;
}
else{
echo &qu