ajax+php寫的無重新整理分頁

來源:互聯網
上載者:User

這裡沒有資料庫 只有代碼  包含資料庫的檔案請到  http://download.csdn.net/detail/huangjianxiang1875/4585847 下載

conn.php

<?php
$hostname="localhost";
$username="root";
$password="";
$db="2012";
mysql_connect($hostname,$username,$password) or die("資料庫連接出現錯誤,請稍後訪問。。。。。。。。");
mysql_select_db($db);
mysql_query("set names utf8");

$db_admin="db_admin";  //登入表
$bkjxpg="bkjxpg";  //資料庫表

?>

fenye.php

<?php
//這兩句話很重要,第一句話告訴瀏覽器返回的資料是xml格式
  header("Content-Type:text/xml;charset=utf-8");
  //告訴瀏覽器不要快取資料
  header("Cache-Control:no-cache");
        include_once("conn.php");
$sql="select * from $bkjxpg where type='評建動態'";
$query=mysql_query($sql);
   $totalsize=mysql_num_rows($query);
$pagesize=2;
$totalpage=ceil($totalsize/$pagesize);
 
 if(empty($_POST['current'])){
 $current=1;
 }else{
 $current=intval($_POST['current']);
 }
 $begin=($current-1)*$pagesize;
 $sql="select * from $bkjxpg where type='評建動態'  order by listtime DESC limit $begin,$pagesize";
 $query=mysql_query($sql);
 $res="<meses>";
 while($records=mysql_fetch_array($query)){
 $time=explode(" ",$records['time']);
 $res.="<mesid>{$records['id']}</mesid><tit>{$records['title']}</tit><time>{$time[0]}</time>";
 }
 $res.="</meses>";
 //file_put_contents("a.txt",$res."\r\n",FILE_APPEND);
 echo $res;
?>

<!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" />
<title></title>


<style type="text/css">
.a1{
color:#333;
text-decoration:none;
}
.a1:hover{
color:#CCC;
}
.qqq{
text-align:center;
margin-top:30px;
}
.waikuang{ width:888px; height:auto;float:left; margin-top:20px; margin-left:80px; display:inline;}


.rightbox02{ width:648px; height:auto; float:left;
}
.rightbox02 ul{ padding:0; margin:0;
}
.rightbox02 ul li{ font-size:14px; color:#52412e; line-height:28px; margin-left:10px; list-style-type:none;
}

</style>
<?php
include_once("conn.php");


$sql="select * from $bkjxpg where type='評建動態'";
$query=mysql_query($sql);
   $totalsize=mysql_num_rows($query);
$pagesize=2;
$totalpage=ceil($totalsize/$pagesize);
?>
<script type="text/javascript" language="javascript">
//建立ajax引擎
function getXmlHttpObject(){
var xmlHttpRequest;
//不同的瀏覽器擷取對象xmlHttpRequest  對象方法不同
if(window.ActiveXObject){
xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttpRequest=new XMLHttpRequest();
}
return xmlHttpRequest;
}


function $(id){
return document.getElementById(id);
}
send(1);
var nowPage=1;
var totalPage=<?php echo $totalpage;?>;
function nevagite(){
var nevagite="";
if(nowPage>1){
nevagite+="<a href=javascript:void(0) onclick=send("+(nowPage-1)+")>上一頁</a>";
}
for(var i=1;i<=totalPage;i++){
   nevagite+=" <a href=javascript:void(0) onclick=send("+i+")>"+i+"</a>";
}
if(nowPage<totalPage){
nevagite+=" <a href=javascript:void(0) onclick=send("+(nowPage+1)+")>下一頁</a>";
}
return nevagite;
}


function send(current){
nowPage=current;
var myXmlHttpRequest=getXmlHttpObject();

if(myXmlHttpRequest){
var url="fenye.php";
var data="current="+current;
//window.alert(data);
myXmlHttpRequest.open("post",url,true);
myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        myXmlHttpRequest.onreadystatechange=function(){
if(myXmlHttpRequest.readyState==4){
if(myXmlHttpRequest.status==200){
$("neirong").innerHTML="";
var mesRes=myXmlHttpRequest.responseXML;
var tits=mesRes.getElementsByTagName("tit");
var time=mesRes.getElementsByTagName("time");
for(var i=0;i<tits.length;i++){
var str="<li><span style=float:right; font-size:14px; margin-right:50px; color:#52412e;>"+time[i].childNodes[0].nodeValue+"</span><a class=r01ba href=#>"+tits[i].childNodes[0].nodeValue+"</a></li>";
$("neirong").innerHTML+=str;
}
$("nevagite").innerHTML=nevagite();

}
}
}
myXmlHttpRequest.send(data);


}
}
</script>
</head>


<body>

             <div class="rightbox02">
                  <ul id="neirong">
                                   
                  </ul>
               <div class="qqq" id="nevagite">
                       
               </div>
             </div>
            
   
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.