


PHP and ajax non-refresh paging implementation code (compatible with multiple browsers)
php与ajax结合实现的无刷新分页的简单例子,供初学的朋友参考。
无刷新分页,兼容IE与Firefox等浏览器。 1、index.php <?php header("Content-Type:text/html;charset=utf-8"); ?> <html> <head> <title>无刷新分页_bbs.it-home.org</title> <style> A{text-decoration:none;} A:link {COLOR:#33CCFF;} A:active {COLOR:#FF6666;} A:visited {COLOR:#33CCFF;} A:hover {COLOR:#FF6699; TEXT-DECORATION: underline;position:relative;left:1px;top:1px} </style> <script language="javascript"> $(document).ready(function(){ changepage(1); }); function changepage(page){ $.post("sql.php",{page:page},function(data){ $("#test").html(data); }); } </script> </head> <body> <ul id="test"></ul> </body> </html> 2、sql.php <?php mysql_connect("","root",""); mysql_select_db("test"); mysql_query("set names utf8"); if(isset($_POST["page"])){ @$page = max(1, intval($_POST["page"])); $pagesize=10; $startindex=($page-1)*$pagesize; $sql="SELECT * FROM test ORDER BY id LIMIT $startindex,$pagesize"; $rec=mysql_query($sql); while($row=mysql_fetch_array($rec)){ $str.="<li>".$row["uname"]."</li>"; } $num=mysql_num_rows(mysql_query("select * from test")); $pagenum=@ceil($num/$pagesize); for($i=1;$i<=$pagenum;$i++){ if($page==$i){ $str.="[".$i."] "; }else{ $str.="".$i." "; } } echo $str; }else{ die(); } ?> 3、test数据库 test表 SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for test -- ---------------------------- DROP TABLE IF EXISTS `test`; CREATE TABLE `test` ( `id` int(10) NOT NULL auto_increment, `uname` char(50) character set utf8 NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=gb2312 COLLATE=gb2312_bin; -- ---------------------------- -- Records -- ---------------------------- INSERT INTO `test` VALUES ('1', 'aaaaaaaaaaa'); INSERT INTO `test` VALUES ('2', 'bbbbbbbbbbbb'); INSERT INTO `test` VALUES ('3', 'cccccccccccc'); INSERT INTO `test` VALUES ('4', 'dddddddddddddddd'); INSERT INTO `test` VALUES ('5', 'eeeeeeeeeee'); INSERT INTO `test` VALUES ('6', 'ffffffffff'); INSERT INTO `test` VALUES ('7', 'ggggggggggggggg'); INSERT INTO `test` VALUES ('8', 'hhhhhhhhhhhh'); INSERT INTO `test` VALUES ('9', 'jjjjjjjjjjjjjjjj'); INSERT INTO `test` VALUES ('10', 'kkkkkkkkkkk'); INSERT INTO `test` VALUES ('11', 'mmmmmmmmmmm'); INSERT INTO `test` VALUES ('12', 'cccccccccccccccccc'); INSERT INTO `test` VALUES ('13', 'bbbbbbbbbbbb'); INSERT INTO `test` VALUES ('14', 'ooooooooooooooooo'); INSERT INTO `test` VALUES ('15', 'pppppppppppp'); INSERT INTO `test` VALUES ('16', 'aaaaaaaaaaaaaaa'); INSERT INTO `test` VALUES ('17', 'ggggggggggggggggg'); INSERT INTO `test` VALUES ('18', 'dddddddddddddddd'); INSERT INTO `test` VALUES ('19', 'cccccccccccccc'); INSERT INTO `test` VALUES ('20', 'xxxxxxxxxx'); INSERT INTO `test` VALUES ('21', 'zzzzzzzzzzzzzzz'); INSERT INTO `test` VALUES ('22', 'oooooooooooooooooooo'); INSERT INTO `test` VALUES ('23', 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii'); INSERT INTO `test` VALUES ('24', 'uuuuuuuuuuuuuuuuuuuuuuuuuuuuu'); INSERT INTO `test` VALUES ('25', 'yyyyyyyyyyyyyyyyyy'); INSERT INTO `test` VALUES ('26', 'ttttttttttttttttttttttttttt'); INSERT INTO `test` VALUES ('27', 'rrrrrrrrrrrrrrrrrrrrrrrr'); INSERT INTO `test` VALUES ('28', 'eeeeeeeeeeeeeeeeeeeee'); INSERT INTO `test` VALUES ('29', 'wwwwwwwwwwwwwwwwwwwww'); INSERT INTO `test` VALUES ('30', 'qqqqqqqqqqqqq'); |

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


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

SublimeText3 English version
Recommended: Win version, supports code prompts!

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.

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.

Notepad++7.3.1
Easy-to-use and free code editor

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