PHP+ajax分页实例简析_PHP
May 28, 2016 pm 01:12 PM
ajax
php
Pagination
本文实例讲述了PHP+ajax分页实现方法。分享给大家供大家参考,具体如下:
HTML代码如下:
<html> <head> <meta http-equiv="Content-Language" content="en" /> <meta name="GENERATOR" content="PHPEclipse 1.0" /> <meta http-equiv="Content-Type" content="text/html; charset=GB2312" /> <title>title</title> <mce:script type='text/javascript'><!-- var http_request=false; function send_request(url){//初始化,指定处理函数,发送请求的函数 http_request=false; //开始初始化XMLHttpRequest对象 if(window.XMLHttpRequest){//Mozilla浏览器 http_request=new XMLHttpRequest(); if(http_request.overrideMimeType){//设置MIME类别 http_request.overrideMimeType("text/xml"); } } else if(window.ActiveXObject){//IE浏览器 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.open("GET",url,true); http_request.onreadystatechange=processrequest; //确定发送请求方式,URL,及是否同步执行下段代码 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(url) { document.getElementById('result').innerHTML="正在读取数据..."; send_request(url); } // --></mce:script> </head> <body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99"> <div id='result'> </div> </body> </html>
Copy after login
php代码如下:
header("Content-type: text/html;charset=GBK");// $link=mysql_connect('localhost','root','root'); mysql_select_db('test'); mysql_query("SET NAMES 'GBK'"); $num=5;//每页显示5条 $sql="select * from article "; //总共有多少记录 $resultt=mysql_query($sql); //获取数据库总记录数 $total=mysql_num_rows($result); echo $total; //总共有多少页 $pagecount=$total/$num; //获取当前页 $currentPage=isset($_GET['page'])?intval($_GET['page']):1; //查询条数 $offset=($currentPage-1)*$num; //下一页 $nexpage=($currentPage==$pagecount?0:$currentPage+1); //</a>"; else $pagecontrol.="下一页"; $pagecontrol.="<a href="javascript:dopage(" mce_href="javascript:dopage("'$url?page=$pagecount')>尾 页</a>"; $result1=mysql_query($strSQL); echo "<table border=1 width=100%>"; echo "<tr>"; echo "<td>编 号</td><td>标 题</td><td>新闻类型</td>"; echo "</tr>"; while($row=mysql_fetch_array($result1)) { echo "<tr>"; echo "<td>$row[id]</td><td>$row[title]</td><td>$row[classname]</td>"; echo "</tr>"; } echo "</table>"; echo "<br/>"; echo $pagecontrol;
Copy after login
希望本文所述对大家PHP程序设计有所帮助。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
