简易分页类
这是一个简单易用的分页类。只需在你原有的程序中加两句、改一句就可以了
先贴代码
paging.php
<?php<br /> class Paging {<br /> public static $count = 0;<br /> public static $size = 0;<br /> public static $page = 0;<br /> static function prepare($sql, $pagesize=10) {<br /> $page = isset($_GET['page']) ? $_GET['page'] : 1;<br /> $pageon = ($page - 1) * $pagesize;<br /> $sql = preg_replace('/select\s/i', '$0SQL_CALC_FOUND_ROWS ', $sql) . " limit $pageon, $pagesize";<br /> $rs = mysql_query($sql);<br /> $p = mysql_query('SELECT FOUND_ROWS()');<br /> list(self::$count) = mysql_fetch_row($p);<br /> self::$size = $pagesize;<br /> self::$page = $page;<br /> return $rs;<br /> }<br /> static function bar($tpl='') {<br /> if(!$tpl) $tpl = '<a href=?reset>首页</a> <a href=?prve>上一页</a> <a href=?next>下一页</a> <a href=?end>尾页</a>';<br /> $count = ceil(self::$count / self::$size);<br /> $page = self::$page;<br /> unset($_GET['page']);<br /> $d = array(<br /> 'reset' => 1,<br /> 'prve' => $page > 1 ? $page - 1 : 1,<br /> 'next' => $page < $count ? $page + 1 : $count,<br /> 'end' => $count,<br /> );<br /> foreach($d as $k=>$v) {<br /> $_GET['page'] = $v;<br /> $tpl = str_replace($k, http_build_query($_GET), $tpl);<br /> }<br /> echo $tpl;<br /> }<br /> }<br />
通常你都有类似这样的语句
$sql =".....";
$rs = mysql_query($sql);
或
$rs = mysql_query("select ....");
你只需改作
include 'paging.php';
$rs = paging::prepare($sql, 每页行数);
在需要出现分页条的地方写入
paging::bar();
就可以了,非常简单!
------解决方案--------------------
前排拜模。
这样的写法还是第一次见到。
$sql = preg_replace('/select\s/i', '$0SQL_CALC_FOUND_ROWS ', $sql) . " limit $pageon, $pagesize";
sql还用preg_replace……
------解决方案--------------------

谢谢分享,确实很方便 ,简单易用 。学习了。
------解决方案--------------------

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

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
