php Ajax paging simple application example_PHP tutorial

WBOY
Release: 2016-07-13 10:44:29
Original
1215 people have browsed it

This article uses Ajax paging to briefly describe how to use php and ajax to implement data non-refresh paging function. Friends in need can refer to it.

Simple mysql data table structure

The code is as follows
 代码如下 复制代码

CREATE TABLE messages
(
msg_id INT PRIMARY KEY AUTO_INCREMENT,
message VARCHAR(150)
);

Copy code

CREATE TABLE messages
(
msg_id INT PRIMARY KEY AUTO_INCREMENT,
message VARCHAR(150)
);

 代码如下 复制代码


JavaScript code

 代码如下 复制代码

if($_POST['page'])
{
$page = $_POST['page'];
$cur_page = $page;
$page -= 1;
$per_page = 15; // Per page records
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
include"db.php";
$query_pag_data = "SELECT msg_id,message from messages LIMIT $start, $per_page";
$result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
$msg = "";
while ($row = mysql_fetch_array($result_pag_data))
{
$htmlmsg=htmlentities($row['message']); //HTML entries filter
$msg .= "

  • " . $row['msg_id'] . " " . $htmlmsg . "
  • ";
    }
    $msg = "
      " . $msg . "
    "; // Content for Data
    /* -----Total count--- */
    $query_pag_num = "SELECT COUNT(*) AS count FROM messages"; // Total records
    $result_pag_num = mysql_query($query_pag_num);
    $row = mysql_fetch_array($result_pag_num);
    $count = $row['count'];
    $no_of_paginations = ceil($count / $per_page);
    /* -----Calculating the starting and endign values for the loop----- */

    //Some Code. Available in download script

    }
    ?>

    Here is the front-end processing of ajax using jquery
    The code is as follows
    Copy code

    load_data.php Here is to get the data sent by ajax and then query mysql through php to return the information
    The code is as follows Copy code
    if($_POST['page'])
    {
    $page = $_POST['page'];
    $cur_page = $page;
    $page -= 1;
    $per_page = 15; // Per page records
    $previous_btn = true;
    $next_btn = true;
    $first_btn = true;
    $last_btn = true;
    $start = $page * $per_page;
    include"db.php";
    $query_pag_data = "SELECT msg_id,message from messages LIMIT $start, $per_page";
    $result_pag_data = mysql_query($query_pag_data) or die('MySql Error' . mysql_error());
    $msg = "";
    while ($row = mysql_fetch_array($result_pag_data))
    {
    $htmlmsg=htmlentities($row['message']); //HTML entries filter
    $msg .= "
  • " . $row['msg_id'] . " " . $htmlmsg . "
  • ";
    }
    $msg = "
      " . $msg . "
    "; // Content for Data
    /* -----Total count--- */
    $query_pag_num = "SELECT COUNT(*) AS count FROM messages"; // Total records
    $result_pag_num = mysql_query($query_pag_num);
    $row = mysql_fetch_array($result_pag_num);
    $count = $row['count'];
    $no_of_paginations = ceil($count / $per_page);
    /* -----Calculating the starting and endign values ​​for the loop----- */ //Some Code. Available in download script }
    ?>

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633092.htmlTechArticleThis article uses Ajax paging to briefly describe how to use php and ajax to implement data non-refresh paging function. If necessary Friends can refer to it. The simple mysql data table structure code is as follows...
    source:php.cn
    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
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template