简易分页类
这是一个简单易用的分页类。只需在你原有的程序中加两句、改一句就可以了
先贴代码
paging.php
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpclass 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……
------解决方案--------------------
谢谢分享,确实很方便 ,简单易用 。学习了。
------解决方案--------------------

本篇文章给大家带来了关于SQL的相关知识,其中主要介绍了SQL Server使用CROSS APPLY与OUTER APPLY实现连接查询的方法,文中通过示例代码介绍的非常详细,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于SQL server的相关知识,其中主要介绍了SQL SERVER没有自带的解析json函数,需要自建一个函数(表值函数),下面介绍关于SQL Server解析/操作Json格式字段数据的相关资料,希望对大家有帮助。

如何优化sql中的orderBy语句?下面本篇文章给大家介绍一下优化sql中orderBy语句的方法,具有很好的参考价值,希望对大家有所帮助。

本篇文章给大家带来了关于SQL server的相关知识,开窗函数也叫分析函数有两类,一类是聚合开窗函数,一类是排序开窗函数,下面这篇文章主要给大家介绍了关于SQL中开窗函数的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下。

本篇文章给大家带来了关于SQL server的相关知识,SQL Server数据库存在一个问题,如果你限制了它的日志文件的大小,那么当数据库日志达到这个大小的时候,数据库就会停止写入日志,下面这介绍了关于SqlServer创建自动收缩事务日志任务的相关资料,希望对大家有帮助。

linux运行sql文件命令是“psql -f test.sql”,其Linux运行sql脚本的方法是:1、使用shell工具登录到安装postgresql的服务器;2、编辑sql脚本内容;3、通过“psql -f test.sql”命令执行“test.sql”脚本即可。

本篇文章给大家带来了关于SQL的相关知识,其中主要介绍了SQL Server跨服务器操作数据库的图文方法,SQL Server Management Studio (SSMS) 是用于管理SQL Server 基础结构的集成环境,下面一起来看一下,希望对大家有帮助。

Vue项目中实现数据的分页和显示优化在Vue项目中,当页面需要展示大量数据时,通常需要进行数据的分页和显示优化以提高用户体验,本文将介绍如何使用Vue实现数据的分页和显示优化,并提供具体的代码示例。一、数据分页数据分页是指将大量数据按照一定的规则分割成多页,并在页面上进行分页显示。Vue项目中可以使用如下步骤来实现数据分页:定义数据源首先,定义一个包含所有数


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

Dreamweaver CS6
Visual web development tools

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.

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.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
