-
二款php mysql 分页代码
本文章提供两种mysql分页代码,分页原是都很简单就是$total = @(int)($sum / $pagesize);$p = (int)$_GET[\'page\'];再到数据库中支limti X,X就成了,代码如下:
- function fenyezhixin($table,$pagesize="",$paixu="",$do="",$wwhere=""){
- if(($table == "news_fabu") or ($table == "product_fabu") or ($table == "message") or ($table == "down_fabu") or ($table == "kucun")){
- $query = @mysql_query("select * from $table $wwhere");
- $pagesize = $pagesize;
- $sum = mysql_num_rows($query);
- if($sum == 0){
- $pagesize = 1;
- }
- if($pagesize=="0"){
- $sum = "1";
- }
- if (@($sum % $pagesize) == 0){
- $total = @(int)($sum / $pagesize);
- }else{
- $total = @(int)($sum / $pagesize) + 1;
- }
- if($total == 0){$total=1;}
- if (isset($_get['page'])){
- $p = (int)$_get['page'];
- }else{
- $p = 1;
- }
- $start = $pagesize * ($p - 1);
- $query = @mysql_query("select * from $table $wwhere order by $paixu limit $start,$pagesize") or die ("数据查询失败2!");
- if ($do == 1){
- $queryarray = array($query,$total,$sum,$p);
- return $queryarray;
- }
- if($do == 2){
- $parray = array($total,$sum,$p);
- return $parray;
- }
- }else{
- $query = @mysql_query("select * from $table $wwhere order by $paixu limit $pagesize") or die ("数据查询失败1!");
- if ($do == 1){
- $queryarray = array($query,$total,$sum,$p);
- return $queryarray;
- }
- if($do == 2){
- $parray = array($total,$sum,$p);
- return $parray;
- }
- }
- }
- //返回分页条
- function fenyedaohang($total="",$sum="",$p="",$menut=""){
- $w = substr($menut,strrpos($menut,"&")+1,2);
- $wr = substr($menut,strrpos($menut,"=")+1,strlen($menut));
- $pindao = $_server["script_name"];$pinstrlen = strrpos($pindao,"/"); $pindao = substr($pindao,$pinstrlen+1,strlen($pindao));
- if($w == "pr"){
- $queryr = mysql_query("select feiye.feiye_what from feiye where feiye.feiye_page = '$pindao'");
- $rows = mysql_fetch_row($queryr); $rrows = $rows[0];
- if(emptyempty($rrows)){
- mysql_query("insert into `feiye` (`feiye_page`, `feiye_what`) values ('$pindao', '$wr')");
- echo "<meta http-equiv='refresh' content='0'>";
- }else{
- if($wr != $rrows){
- mysql_query("update `feiye` set `feiye_what`='$wr' where (`feiye_page`='$pindao')");
- echo "<meta http-equiv='refresh' content='0'>";
- }
- }
- }
- if($w == "ne"){
- $queryr = mysql_query("select feiye.feiye_what from feiye where feiye.feiye_page = '$pindao'");
- $rows = mysql_fetch_row($queryr); $rrows = $rows[0];
- if(emptyempty($rrows)){
- mysql_query("insert into `feiye` (`feiye_page`, `feiye_what`) values ('$pindao', '$wr')");
- echo "<meta http-equiv='refresh' content='0'>";
- }else{
- if($wr != $rrows){
- mysql_query("update `feiye` set `feiye_what`='$wr' where (`feiye_page`='$pindao')");
- echo "<meta http-equiv='refresh' content='0'>";
- }
- }
- }
- echo "共"."$total"."页 "."记录"."$sum"."条 当前"."$p"."/"."$total"."页 ";
- if($total == 1){
- echo "<font class="page">首页</font>";
- }else{
- echo "<a href='?page=1&menu=$menut' class="page">首页</a>"." ";
- }
- if ($p > 1){
- $prev = $p - 1;
- echo "<a href='?page=$prev&menu=$menut' class="page">上一页</a>"." ";
- }else{
- echo "<font class="page">上一页</font>"." ";
- }
- $page = $_get["page"];
- $pagesum = $page+5;
- if($total >= 11){
- if($pagesum <=11 ){
- $pagesum = 11;
- }
- }
- if($pagesum >= $total){
- $pagesum = $total;
- }
- $pagestart = $page - 5;
- if($pagestart <= 0){
- $pagestart = 1;
- }
- if($total >= 11 and ($total-4) <= $page){
- $pagestart = $total-10;
- }
- for($i=$pagestart;$i<=$pagesum;$i++){
- if($i == $p){
- echo "<font color=cccccc> $i </font>";
- }else{
- echo "<a href='?page=$i&menu=$menut' class="page" >$i</a>";
- }
- }
- if ($p < $total){
- $next = $p + 1;
- echo " <a href='?page=$next&menu=$menut' class="page" >下一页</a>"." ";
- }else{
- echo "<font class="page" >下一页</font>"." ";
- }
- if($total == 1){//开源代码phpfensi.com
- echo "<font class="page">尾页</font>";
- }else{
- echo "<a href='?page=$total&menu=$menut' class="page">尾页</a>";
- }
- }
出处:http://www.phpfensi.com/php/20140815/4256.html
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式