Today I was watching Momo’s explanation of paging. It seemed like no one had posted in the original area for a long time, so I just expanded Momo’s one and gave a PHP+AJAX paging demonstration. Okay, that’s it. First of all, we are still basic. AJAX development framework:
Copy code The code is as follows:
var http_request=false;
function send_request(url){//Initialization, specify processing function, function to send request
http_request=false;
//Start Initialize the XMLHttpRequest object
if(window. rideMimeType("text/xml");
}
}
else if(window.ActiveXObject){//IE browser
try{
http_request=new ActiveXObject("Msxml2.XMLHttp");
}catch(e){
try{
http_request=new ActiveXobject(" Microsoft.XMLHttp");
}catch(e){}
}
}
if(!http_request){//Exception, failed to create object instance
window.alert("Failed to create XMLHttp object!");
return false ;
}
http_request.
//Determine the request method, URL, and whether to execute the next code synchronously
http_request.open("GET",url,true);
http_request.send(null);
}
//Processing Function that returns information
function processrequest(){
if(http_request.readyState==4){//Determine the object status
if(http_request.status==200){//The information has been returned successfully, start processing the information
document. getElementById(reobj).innerHTML=http_request.responseText;
} using. ");
}
}
}
function dopage(obj,url){
document.getElementById(obj).innerHTML="Reading data...";
send_request(url);
reobj=obj;
}
I display the content in a div. When the page turning action occurs, I use AJAX to update the DIV to achieve the page turning effect. This is the content display page code:
The code is as follows:
header("Content-type: text/html;charset=GBK");//输出编码,避免中文乱码
?>
<script></script>
$page=isset($_GET['page'])?intval($_GET['page']):1; //这句就是获取page=18中的page的值,假如不存在page,那么页数就是1。
$num=10; //每页显示10条数据
$db=mysql_connect("localhost","root","7529639"); //创建数据库连接
mysql_select_db("cr_download"); //选择要操作的数据库
/*
首先咱们要获取数据库中到底有多少数据,才能判断具体要分多少页,具体的公式就是
总数据库除以每页显示的条数,有余进一。
也就是说10/3=3.3333=4 有余数就要进一。
*/
$result=mysql_query("select * from cr_userinfo");
$total=mysql_num_rows($result); //查询所有的数据
$url='test.php';//获取本页URL
//页码计算
$pagenum=ceil($total/$num); //获得总页数,也是最后一页
$page=min($pagenum,$page);//获得首页
$prepg=$page-1;//上一页
$nextpg=($page==$pagenum ? 0 : $page+1);//下一页
$offset=($page-1)*$num; //获取limit的第一个参数的值,假如第一页则为(1-1)*10=0,第二页为(2-1)*10=10。
//开始分页导航条代码:
$pagenav="显示第 ".($total?($offset+1):0)."-".min($offset+10,$total)." 条记录,共 $total 条记录 ";
//如果只有一页则跳出函数:
if($pagenum$pagenav.=" 首页 ";
if($prepg) $pagenav.=" 前页 "; else $pagenav.=" 前页 ";
if($nextpg) $pagenav.=" 后页 "; else $pagenav.=" 后页 ";
$pagenav.=" 尾页 ";
$pagenav.=" 页,共 $pagenum 页";
//假如传入的页数参数大于总页数,则显示错误信息
If($page>$pagenum){
Echo "Error : Can Not Found The page ".$page;
Exit;
}
$info=mysql_query("select * from cr_userinfo limit $offset,$num"); //获取相应页数所需要显示的数据
While($it=mysql_fetch_array($info)){
Echo $it['username'];
echo "
";
} //显示数据
echo"
";
echo $pagenav;//输出分页导航
?>
The key to turning pages is to call the dopage() function when turning pages, and then use the callback information to update the content in the div. Server-side core code:
Copy code The code is as follows:
header("Content-type: text/html;charset=GBK");//Output encoding to avoid Chinese garbled characters
$ page=isset($_GET['page'])?intval($_GET['page']):1; //This sentence is to get the value of page in page=18. If page does not exist, then the number of pages is 1.
$num=10; elect_db("cr_download"); //Select to Database of operation
/*
First of all, we need to get how much data there is in the database to determine how many pages it needs to be divided into. The specific formula is
The total database is divided by the number of items displayed on each page, and the remainder is rounded up to one.
That is to say, 10/3=3.3333=4 If there is a remainder, we must round it up by one.
*/
$result=mysql_query("select * from cr_userinfo");
$total=mysql_num_rows($result); //Query all data
$url='test.php';//Get the URL of this page
// Page code calculation p $ Pagenum = CEIL ($ Total/$ Num); // Get the total page number, which is the last page
$ page = min ($ pagenum, $ page); // gets homepage
$ prepg = $ page-1;//Previous page
$nextpg=($page==$pagenum ? 0 : $page+1);//Next page
$offset=($page-1)*$num; Get the value of the first parameter of limit. If the first page is (1-1)*10=0, the second page is (2-1)*10=10.
//Start paging navigation bar code:
$pagenav="Display page ".($total?($offset+1):0)."-".min ($offset+10,$total)." records, total $total records ";
//If there is only one page, jump out of the function:
if($pagenum $pagenav.=" Homepage ";
if($prepg) $pagenav.=" Previous page "; else $pagenav.=" Previous page ";
if($nextpg) $pagenav.= " Next page "; else $pagenav.=" Next page ";
$pagenav.=" Last page ";
$pagenav.=" Pages, total $pagenum pages ";
//If the page number parameter passed in is greater than the total number of pages, an error message will be displayed
If($page>$pagenum){
"Echo "Error: Can Not Found The page ".$page;
Exit;
}
$info=mysql_query("select * from cr_userinfo limit $offset,$num"); //Get the data to be displayed for the corresponding page number
While($it=mysql_fetch_array($info)){
Echo $it[ 'username'];
echo "
";
} echo"
echo $pagenav;//Output paging navigation
?>
The above has introduced the PHP paging navigation Ajax PHP paging demonstration, including the content of PHP paging navigation. I hope it will be helpful to friends who are interested in PHP tutorials.

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
