二款php mysql 分页代码
发布:smiling 来源: PHP粉丝网 添加日期:2014-08-15 14:19:53 浏览: 评论:0
本文章提供两种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>";
- }
- }
Tags: php mysql 分页代码
- 上一篇:两款实用php分页代码
- 下一篇:php mysql 分页函数
相关文章
- ·php分页代码与分页原理(2013-11-12)
- ·PHP分页显示制作(2013-11-13)
- ·PHP实现翻页跳转功能(2013-11-13)
- ·自定义PHP分页函数(2013-11-13)
- ·小谈PHP&MYSQL分页原理及实现(2013-11-13)
- ·php中分页显示文章标题(2013-12-10)
- ·PHP MySQL分页显示(2013-12-10)
- ·一款php分页代码(2013-12-16)
- ·php分页代码(2013-12-16)
- ·PHP+AJAX无刷新分页实现代码详解(2014-01-03)
- ·PHP 分页代码与分页原理解析(2014-01-06)
- ·php文章内容分页实例程序(2014-01-07)
- ·php中分页程序之基于留言板详解(2014-01-15)
- ·php分页可利用表格来分页类(2014-01-15)
- ·简单入门级php分页代码(2014-05-10)
- ·PHP简单分页函数代码总结(2014-06-18)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)