PHP+ajax分頁實(shí)例簡析
本文實(shí)例講述了PHP+ajax分頁實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:
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){//初始化,指定處理函數(shù),發(fā)送請求的函數(shù) http_request=false; //開始初始化XMLHttpRequest對象 if(window.XMLHttpRequest){//Mozilla瀏覽器 http_request=new XMLHttpRequest(); if(http_request.overrideMimeType){//設(shè)置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){//異常,創(chuàng)建對象實(shí)例失敗 window.alert("創(chuàng)建XMLHttp對象失??!"); return false; } http_request.open("GET",url,true); http_request.onreadystatechange=processrequest; //確定發(fā)送請求方式,URL,及是否同步執(zhí)行下段代碼 http_request.send(null); } //處理返回信息的函數(shù) function processrequest(){ if(http_request.readyState==4){//判斷對象狀態(tài) if(http_request.status==200){//信息已成功返回,開始處理信息 document.getElementById('result').innerHTML=http_request.responseText; } else{ //頁面不正常 alert("您所請求的頁面不正常!"); } } } function dopage(url) { document.getElementById('result').innerHTML="正在讀取數(shù)據(jù)..."; send_request(url); } // --></mce:script> </head> <body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99"> <div id='result'> </div> </body> </html>
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); //獲取數(shù)據(jù)庫總記錄數(shù) $total=mysql_num_rows($result); echo $total; //總共有多少頁 $pagecount=$total/$num; //獲取當(dāng)前頁 $currentPage=isset($_GET['page'])?intval($_GET['page']):1; //查詢條數(shù) $offset=($currentPage-1)*$num; //下一頁 $nexpage=($currentPage==$pagecount?0:$currentPage+1); //上一頁 $prepg=$currentPage-1; $url='ajax.php'; //根據(jù)條數(shù)查詢信息 $strSQL="select * from article limit $offset,$num"; $pagecontrol="當(dāng)前第".$currentPage."頁" ; $pagecontrol.="共".$pagecount."頁"; $pagecontrol.="<a href="javascript:dopage(" mce_href="javascript:dopage("'$url?page=1')>首 頁</a> "; if($prepg) $pagecontrol.=" <a href="javascript:dopage(" mce_href="javascript:dopage("'$url?page=$prepg');>上一頁</a> "; else $pagecontrol.=" 上一頁 "; if($nexpage) $pagecontrol.="<a href="javascript:dopage(" mce_href="javascript:dopage("'$url?page=$nexpage');>下一頁</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>編 號(hào)</td><td>標(biāo) 題</td><td>新聞?lì)愋?lt;/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;
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
- Ajax+smarty技術(shù)實(shí)現(xiàn)無刷新分頁
- 利用jQuery中的ajax分頁實(shí)現(xiàn)代碼
- jQuery ajax分頁插件實(shí)例代碼
- 詳解PHP+AJAX無刷新分頁實(shí)現(xiàn)方法
- jQuery+Ajax實(shí)現(xiàn)無刷新分頁
- 使用Jquery+Ajax+Json如何實(shí)現(xiàn)分頁顯示附JAVA+JQuery實(shí)現(xiàn)異步分頁
- jquery插件pagination實(shí)現(xiàn)無刷新ajax分頁
- jQuery+Ajax+PHP+Mysql實(shí)現(xiàn)分頁顯示數(shù)據(jù)實(shí)例講解
- js實(shí)現(xiàn)ajax分頁完整實(shí)例
相關(guān)文章
PHP實(shí)現(xiàn)數(shù)組的笛卡爾積運(yùn)算示例
這篇文章主要介紹了PHP實(shí)現(xiàn)數(shù)組的笛卡爾積運(yùn)算,結(jié)合實(shí)例形式分析了php數(shù)組的笛卡爾積運(yùn)算相關(guān)實(shí)現(xiàn)與使用技巧,需要的朋友可以參考下2017-12-12PHP常用工具函數(shù)小結(jié)【移除XSS攻擊、UTF8與GBK編碼轉(zhuǎn)換等】
這篇文章主要介紹了PHP常用工具函數(shù),結(jié)合實(shí)例形式總結(jié)分析了php移除XSS攻擊、以及php操作UTF8與GBK編碼轉(zhuǎn)換等相關(guān)操作自定義函數(shù)實(shí)現(xiàn)方法,需要的朋友可以參考下2019-04-04PHP使用mysql_fetch_object從查詢結(jié)果中獲取對象集的方法
這篇文章主要介紹了PHP使用mysql_fetch_object從查詢結(jié)果中獲取對象集的方法,實(shí)例分析了php操作mysql_fetch_object查詢數(shù)據(jù)庫的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03強(qiáng)烈聲明: 不要使用(include/require)_once
本篇文章是對不要使用(include/require)_once的原因進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06php下關(guān)于Cannot use a scalar value as an array的解決辦法
已經(jīng)定義過的一個(gè)布爾型變量在下面被我直接當(dāng)數(shù)組來調(diào)用了,所以就出現(xiàn)錯(cuò)誤了2010-08-08phpMyAdmin出現(xiàn)無法載入 mcrypt 擴(kuò)展,請檢查PHP配置的解決方法
出現(xiàn)以下幾種情況后可能會(huì)造成運(yùn)行phpmyadmin程序提示 無法載入 mcrypt 擴(kuò)展,請檢查 PHP 配置 的 錯(cuò)誤提示2012-03-03