1. First master page ajax_pag.php
The code is as follows:
<! DOCTYPE html>
2. Then do the paging query JS page ajax_pag.js
The code is as follows:
Ajax paging begins var ts = 10; Number of bars displayed per page var page = 1; Current page $ (document). Ready (function (e) {//page load data load (); Load the paging list loadlist (); $ ("#ck"). Click (function () {//page load data load (); Load the paging list loadlist ();})}) Method of loading Data function load () {var GJZ = $ ("#key"). Val (); $.ajax ({async:false, url: "pagechuli.php", data: {Page:page,ts:ts,gjz:gjz},//page is the number of pages displayed; Type: "JSON", success:function (data) {var str = ""; For (var k in data) {str + = "<tr><td>" +data[k][0]+ "</td><td>" +data[k][1]+ "</td><td > "+data[k][2]+" </td></tr> ";} $ ("#list"). html (str); Put the spliced string in the Thody to be displayed}})}//load page list function loadlist () {var str = ""; Prev str+= "<li><a id= ' prev ' >« </a></li> "; Load list for (Var i=page-4; i<page+5; i++) {//restriction if (i>0 && I<=zys ()) {//Determine current page if (i==page) {str+= "<li class= ' active ' ><a> "+i+" </a></li> ";} ElSE {str+= "<li><a class= ' item ' >" +i+ "</a></li>";}} }//next str+= "<li><a id= ' Next ' >» </a></li> "; $ ("#fenye"). html (str); $ ("#prev"). Click (function () {if (page>1) {page--;} Page load data load (); Load the paging list loadlist ();}) $ (". Item"). Click (function () {var p = $ (this). text (); The string is taken and converted to an integer page = parseint (p); Page load data load (); Load the paging list loadlist ();}) $ ("#next"). Click (function () {if (Page<zys ()) {page++;} Page load data load (); Load the paging list loadlist ();}) }//Total pages Function Zys () {var Zys = 0; $.ajax ({async:false, url: "zyschuli.php", DataType: "TEXT", success:function (data) {Zys = Math.ceil (data/ts);}}); return Zys;}
3. Finally do paging query processing page pagechuli.php
The code is as follows:
<?php $gjz = $_post["GJZ"]; $page = $_post["page"]; Get the page display value $ts = $_post["ts"]; Gets the number of bars per page display value require_once "./dbda.class.php"; $db = new Dbda (); $TJ = "1=1"; if (!empty ($_post["GJZ")) { $GJZ = $_post["GJZ"]; $TJ = "AreaName"% { $gjz}% ' or areacode like '% { $gjz}% ' or parentareacode like '% { $gjz}% ' ";} $TG = ($page-1) * $TS; Each page shows $ts data, which shows the $TG data of the current page. $sql = "SELECT * from Chinastates where { $tj}limit { $tg}, { $ts}"; echo $db->jsonquery ($sql, 0)
Widget: Processing page for total pages zyschuli.php
<?php require_once "./dbda.class.php"; $db = new Dbda (); $sql = "SELECT count (*) from chinastates"; echo $db->strquery ($sql, 0);
Effect
Keyword query: