简易分页种
简易分页类
这是一个简单易用的分页类。只需在你原有的程序中加两句、改一句就可以了
先贴代码
paging.php
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><?php class Paging { public static $count = 0; public static $size = 0; public static $page = 0; static function prepare($sql, $pagesize=10) { $page = isset($_GET['page']) ? $_GET['page'] : 1; $pageon = ($page - 1) * $pagesize; $sql = preg_replace('/select\s/i', '$0SQL_CALC_FOUND_ROWS ', $sql) . " limit $pageon, $pagesize"; $rs = mysql_query($sql); $p = mysql_query('SELECT FOUND_ROWS()'); list(self::$count) = mysql_fetch_row($p); self::$size = $pagesize; self::$page = $page; return $rs; } static function bar($tpl='') { if(!$tpl) $tpl = '<a href=?reset>首页 <a href="?prve">上一页</a> <a href="?next">下一页</a> <a href="?end">尾页</a>'; $count = ceil(self::$count / self::$size); $page = self::$page; unset($_GET['page']); $d = array( 'reset' => 1, 'prve' => $page > 1 ? $page - 1 : 1, 'next' => $page $count, ); foreach($d as $k=>$v) { $_GET['page'] = $v; $tpl = str_replace($k, http_build_query($_GET), $tpl); } echo $tpl; } }
通常你都有类似这样的语句
$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……
------解决方案--------------------
谢谢分享,确实很方便 ,简单易用 。学习了。
------解决方案--------------------

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

BLOBstoresbinarydatalikeimages,audio,orPDFsasrawbyteswithoutcharacterencoding,whileCLOBstoreslargetextsuchasarticlesorJSONusingcharacterencodinglikeUTF-8andsupportsstringoperations;2.Bothcanhandleuptogigabytesofdatadependingonthedatabase,butperforman

TofindthesumofacolumninSQL,usetheSUM()function,whichreturnsthetotalofallnumericvaluesinaspecifiedcolumnwhileignoringNULLs;1.Usebasicsyntax:SELECTSUM(column_name)ASaliasFROMtable_name;2.Ensurethecolumnhasnumericdatatoavoiderrors;3.ApplyWHEREtofilterro

ThefirstdayoftheyearisobtainedbyconstructingortruncatingtoJanuary1stofthegivenyear,andthelastdayisDecember31stofthesameyear,withmethodsvaryingbydatabasesystem;2.Fordynamiccurrentyeardates,MySQLusesDATE_FORMATorMAKEDATE,PostgreSQLusesDATE_TRUNCorDATE_

SQL execution context refers to the identity or role when running SQL statements, which determine which resources and operation permissions can be accessed. Permission setting should follow the principle of minimum permissions, and common permissions include SELECT, INSERT, EXECUTE, etc. To troubleshoot permission issues, you need to confirm the login name, role permissions, EXECUTEAS settings and schema authorization. Performing context switching can be implemented through EXECUTEAS, but attention should be paid to user existence, permission granting and performance security impact. It is recommended to avoid arbitrarily assigning db_owner or sysadmin roles. The application account should only access necessary objects and be authorized through schema.

Aself-joinisusedtocomparerowswithinthesametable,suchasinhierarchicaldatalikeemployee-managerrelationships,bytreatingthetableastwoseparateinstancesusingaliases,asdemonstratedwhenlistingemployeesalongsidetheirmanagers'nameswithaLEFTJOINtoincludetop-lev

TheALTERTABLEstatementisusedtomodifyanexistingtable’sstructurewithoutrecreatingit;1.AddanewcolumnusingADDCOLUMN;2.DropacolumnwithDROPCOLUMN,whichalsodeletesitsdata;3.RenameacolumnusingRENAMECOLUMN,withsyntaxconsistentinMySQL,SQLServer,andPostgreSQL;4

The syntax for creating a view is the CREATEVIEWview_nameASSELECT statement; 2. The view does not store actual data, but is based on the real-time query results of the underlying table; 3. The view can be modified using CREATEORREPLACEVIEW; 4. The view can be deleted through DROPVIEW; 5. The view is suitable for simplifying complex queries, providing data access control, and maintaining interface consistency, but attention should be paid to performance and logic, and finally ends with a complete sentence.

AFULLOUTERJOINreturnsallrowsfrombothtables,withNULLswherenomatchexists;1)Itcombinesmatchingrecordsandincludesunmatchedrowsfrombothleftandrighttables;2)Itisusefulfordatareconciliation,mergereports,andidentifyingmismatches;3)Notalldatabasessupportitnat
