Home >Backend Development >PHP Tutorial >php Ajax paging simple application example_PHP tutorial
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
|
Copy code
|
||||||||||
CREATE TABLE messages
JavaScript code
|
The code is as follows | Copy code |
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 .= " } $msg = "
/* -----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 } ?> |