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.

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor
