下面只是一个测试,在实际应用中,可能这种方法会比较占系统资源,不建意利用这样的方法处理分页效果,代码如下:
- var http_request=false;
- function send_request(url){
- http_request=false;
-
- if(window.xmlhttprequest){
- http_request=new xmlhttprequest();
- if(http_request.overridemimetype){
- http_request.overridemimetype("text/xml");
- }
- }
- else if(window.activexobject){
- try{
- http_request=new activexobject("msxml2.xmlhttp");
- }catch(e){
- try{
- http_request=new activexobject("microsoft.xmlhttp");
- }catch(e){}
- }
- }
- if(!http_request){
- window.alert("创建xmlhttp对象失败!");
- return false;
- }
- http_request.onreadystatechange=processrequest;
-
- http_request.open("get",url,true);
- http_request.send(null);
- }
-
- function processrequest(){
- if(http_request.readystate==4){
- if(http_request.status==200){
- document.getelementbyid('result').innerhtml=http_request.responsetext;
- }
- else{
- alert("您所请求的页面不正常!");
- }
- }
- }
- function dopage(obj,url){
- document.getelementbyid(obj).innerhtml="正在读取数据...";
- send_request(url);
- reobj=obj;
- }
php html处理代码:
- <div id="result">
- <?php
- $classid=$_request['classid'];
-
-
- $page=isset($_get['page'])?intval($_get['page']):1;
- $num=10;
-
- require "conn.php";
- mysql教程_select_db($database_lr, $lr);
-
-
-
-
-
-
- $result=mysql_query("select * from blog where classid='$classid'");
- $total=mysql_num_rows($result);
-
- $url='show_main.php';
-
-
- $pagenum=ceil($total/$num);
- $page=min($pagenum,$page);
- $prepg=$page-1;
- $nextpg=($page==$pagenum ? 0 : $page+1);
- $offset=($page-1)*$num;
-
-
- $pagenav=$page."/".$pagenum." <b> ".($total?($offset+1):0)."</b>-<b>".min($offset+10,$total)."</b> total $total ";
-
-
- if($page==1) {
- $pagenav.="first ";
- }
- else
- {$pagenav.="<a href=网页特效:dopage('result','$url?classid=$classid&page=1');>first</a> ";}
- if($prepg) $pagenav.=" <a href=javascript:dopage('result','$url?classid=$classid&page=$prepg');>prev</a> "; else $pagenav.=" prev ";
- if($nextpg) $pagenav.=" <a href=javascript:dopage('result','$url?classid=$classid&page=$nextpg');>next</a> "; else $pagenav.=" next ";
- if ($pagenum>$page){
- $pagenav.=" <a href=javascript:dopage('result','$url?classid=$classid&page=$pagenum');>last</a> ";
- }
- else{
- $pagenav.=" last";
- }
- $pagenav.=" total page $pagenum ";
-
-
- if($page>$pagenum){
- echo "error : can not found the page ".$page;
- exit;
- }
-
- $info=mysql_query("select * from blog where classid='$classid' order by id desc limit $offset,$num");
-
- if ($total>0)
- {
- while($it=mysql_fetch_array($info)){
- echo $it['title']." (".$it['updatetime'].")";
- echo "<br>";
- echo $it['content'];
- echo "<br>";
- }
- echo"<br>";
- echo $pagenav;
- }
- else
- {
- echo"no comment.";
- }
- ?>
- </div>
|