php中的分页跳转函@本文来*源gaodai#ma#com搞*!代#%^码$网*数,点击时没反应
显示页面:
<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>
<?php
session_start() ;
error_reporting(E_ALL & ~E_NOTICE);
?>
<body onl oad=”viewpage(2)”>
<?php
echo $_SESSION[“name”].”的聊天记录” ;
?>
数据发送页面: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 “
聊天内容 | 聊天时间 |
---|---|
“.$content[$a].” | “.$date[$a].” |
” ;
echo “
” ; echo “第”.$page.”页/总共”.$pages.”页 | 总”.$numrows.”条记录 ” ; if($page==1){ echo “首页|上一页|” ; } else{ echo “首页|” ; echo “上一页|” ; } if($page==$pages){ echo “下一页|尾页” ; } else{ echo “下一页|” ; echo “尾页” ; |