Using jQuery + Ajax in PHP to implement multi-function paging query, jqueryajax

Source: Internet
Author: User

Using jQuery + Ajax in PHP to implement multi-function paging query, jqueryajax

1. First, the master page Ajax_pag.php

The Code is as follows:

<! DOCTYPE html> 

2. query the JS page by page.

The Code is as follows:

// Ajax pagination starts var ts = 10; // number of lines displayed on each page var page = 1; // current page $ (document ). ready (function (e) {// Load data Load () on the page; // Load the paging list Loadlist (); $ ("# ck "). click (function () {// Load data on the page Load (); // Load the paging list Loadlist () ;})} // function Load () {var gjz = $ ("# key "). val (); $. ajax ({async: false, url: "pagechuli. php ", data: {page: page, ts: ts, gjz: gjz}, // page indicates the number of displayed pages, and ts indicates the number of displayed items. type:" POST ", dataType: "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" character .html (str); // put the concatenated string in the thody to be displayed})} // load the paging list function Loadlist () {var str = ""; // str + = "<li> <a id = 'prev'> & laquo; </a> </li> "; // load the list for (var I = page-4; I <page + 5; I ++) {// restriction condition if (I> 0 & I <= zys () {// judge the current page if (I = page) {str + = "<li class = 'active'> <a>" + I + "</a> </li> ";} else {str + = "<li> <a class = 'item'>" + I + "</a> </li> ";}}} // str + = "<li> <a id = 'Next'> & raquo; </a> </li> "; $ ("# fenye" pai.html (str); $ ("# prev "). click (function () {if (page> 1) {page --;} // Load data on the page; // Load the page list Loadlist ();}) $ (". item "). click (function () {var p = $ (this ). text (); // The obtained string is converted to an integer page = parseInt (p); // Load data on the page (); // load the paging list Loadlist () ;}) $ ("# next "). click (function () {if (page <zys () {page ++;} // Load data on the page (); // load the paging list Loadlist () ;}} // total number of 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. pagechuli. php

The Code is as follows:

<? Php $ gjz = $ _ POST ["gjz"]; $ page = $ _ POST ["page"]; // get the page display value $ ts =$ _ POST ["ts"]; // obtain the display value require_once "for each page ". /DBDA. class. php "; $ db = new DBDA (); $ tj =" 1 = 1 "; if (! Empty ($ _ POST ["gjz"]) {$ gjz = $ _ POST ["gjz"]; $ tj = "areaname like '% {$ gjz} %' or areacode like '% {$ gjz} %' or parentareacode like '% {$ gjz} % '";} $ tg = ($ page-1) * $ ts; // $ ts data is displayed on each page. $ tg data is displayed on the current page. $ SQL = "select * from chinastates where {$ tj} limit {$ tg}, {$ ts}"; echo $ db-> JsonQuery ($ SQL, 0)

Small plug-in: Processing page of the total number of pages zyschuli. php

<?phprequire_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.