A method of using Jquery+ajax in PHP to realize multi-function operation of paging query

Source: Internet
Author: User
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 ' >&laquo;    </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 ' >&raquo;    </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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.