当前位置:Gxlcms > PHP教程 > php分页种代码

php分页种代码

时间:2021-07-01 10:21:17 帮助过:29人阅读

php分页类代码
1001, 'gid'=>2008));
	 * 	
	 *  
输出: [上一页] 1<< [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] >>10 [下一页] */ public static function split1($allItemTotal, $currPageNum, $pageSize, $pageName='', $getParamList = array()){ if ($allItemTotal == 0) return ""; //页面名称 if ($pageName==''){ $url = $_SERVER['PHP_SELF']."?page="; } else { $url = $pageName."?page="; } //参数 $urlParamStr = ""; foreach ($getParamList as $key => $val) { $urlParamStr .= "&". $key ."=". $val; } //计算总页数 $pagesNum = ceil($allItemTotal/$pageSize); //第一页显示 $firstPage = ($currPageNum <= 1) ? $currPageNum ."<<" : "1<<"; //最后一页显示 $lastPage = ($currPageNum >= $pagesNum)? ">>". $currPageNum : ">>". $pagesNum .""; //上一页显示 $prePage = ($currPageNum <= 1) ? "上页" : "[上一页]"; //下一页显示 $nextPage = ($currPageNum >= $pagesNum) ? "下页" : "[下一页]"; //按页显示 $listNums = ""; for ($i=($currPageNum-4); $i<($currPageNum+9); $i++) { if ($i < 1 || $i > $pagesNum) continue; if ($i == $currPageNum) $listNums.= "[".$i."] "; else $listNums.= " [". $i ."] "; } $returnUrl = $prePage ." ". $firstPage ." ". $listNums ." ". $lastPage ." ". $nextPage; return $returnUrl; } /** * 分页显示样式二 * * @param int $allItemTotal 所有记录数量 * @param int $currPageNum 当前页数量 * @param int $pageSize 每页需要显示记录的数量 * @param string $pageName 当前页面的地址, 如果为空则由系统自动获取,缺省为空 * @param array $getParamList 页面中需要传递的URL参数数组, 数组中key代表变量民,value代表变量值 * @return string 返回最后解析出分页HTML代码, 可以直接使用 * @example * echo pageStyle1(50, 2, 10, 's.php', array('id'=>1, 'name'=>'user')); * * 输出:上一页 1 2 3 4 5 下一页 [2] [GO] */ public static function split2($allItemTotal, $currPageNum, $pageSize, $pageName='', $getParamList = array()){ if ($allItemTotal == 0) return ""; //页面名称 if ($pageName==''){ $url = $_SERVER['PHP_SELF']."?page="; } else { $url = $pageName."?page="; } //参数 $urlParamStr = ""; foreach ($getParamList as $key => $val) { $urlParamStr .= "&". $key ."=". $val; } //计算总页数 $pagesNum = ceil($allItemTotal/$pageSize); //上一页显示 $prePage = ($currPageNum <= 1) ? "上一页" : "上一页"; //下一页显示 $nextPage = ($currPageNum >= $pagesNum) ? "下一页" : "下一页"; //按页显示 $listNums = ""; for ($i=($currPageNum-4); $i<($currPageNum+9); $i++) { if ($i < 1 || $i > $pagesNum) continue; if ($i == $currPageNum) $listNums.= " ".$i." "; else $listNums.= " ". $i ." "; } $returnUrl = $prePage ." ". $listNums ." ". $nextPage; $gotoForm = '  '; return $returnUrl . $gotoForm; } /** * 分页显示样式三 * * @param int $allItemTotal 所有记录数量 * @param int $currPageNum 当前页数量 * @param int $pageSize 每页需要显示记录的数量 * @param string $pageName 当前页面的地址, 如果为空则由系统自动获取,缺省为空 * @param array $getParamList 页面中需要传递的URL参数数组, 数组中key代表变量民,value代表变量值 * @return string 返回最后解析出分页HTML代码, 可以直接使用 * @example * echo pageStyle1(50, 2, 10, 's.php', array('id'=>1, 'name'=>'user')); * * 输出:上一页 下一页 */ public static function split3($allItemTotal, $currPageNum, $pageSize, $pageName='', $getParamList = array()){ if ($allItemTotal == 0) return ""; //页面名称 if ($pageName==''){ $url = $_SERVER['PHP_SELF']."?page="; } else { $url = $pageName."?page="; } //参数 $urlParamStr = ""; foreach ($getParamList as $key => $val) { $urlParamStr .= "&". $key ."=". $val; } //计算总页数 $pagesNum = ceil($allItemTotal/$pageSize); //上一页显示 $prePage = ($currPageNum <= 1) ? "上一页" : "上一页"; //下一页显示 $nextPage = ($currPageNum >= $pagesNum) ? "下一页" : "下一页"; $returnUrl = $prePage ." ". $nextPage; return $returnUrl; } /** * 分页显示4 * * @param int $allItemTotal 所有记录数量 * @param int $currPageNum 当前页数量 * @param int $pageSize 每页需要显示记录的数量 * @param string $pageName 当前页面的地址, 如果为空则由系统自动获取,缺省为空 * @param array $getParamList 页面中需要传递的URL参数数组, 数组中key代表变量民,value代表变量值 * @return string 返回最后解析出分页HTML代码, 可以直接使用 * @example * echo pageStyle1(50, 2, 10, 's.php', array('id'=>1, 'name'=>'user')); * * 输出:第2/50页 上一页 1 2 3 4 5 下一页 跳到 [ ] 页 [GO] */ public static function split4($allItemTotal, $currPageNum, $pageSize, $pageName='', $getParamList = array()){ if ($allItemTotal == 0) return ""; //页面名称 if ($pageName==''){ $url = $_SERVER['PHP_SELF']."?page="; $formUrl = $_SERVER['PHP_SELF']."?"; } else { $url = $pageName."?page="; $formUrl = $pageName."?"; } //参数 $urlParamStr = ""; foreach ($getParamList as $key => $val) { $urlParamStr .= "&". $key ."=". $val; } $formUrl .= $urlParamStr ."&page="; //计算总页数 $pagesNum = ceil($allItemTotal/$pageSize); //上一页显示 $prePage = ($currPageNum <= 1) ? "上一页" : "上一页"; //下一页显示 $nextPage = ($currPageNum >= $pagesNum) ? "下一页" : "下一页"; //按页显示 $listNums = "\n"; $returnUrl = $prePage .' '. $nextPage . ' 共有'.$pagesNum.'页 跳到 '.$listNums ." 页 "; $script =<<1, 'name'=>'user')); * * 输出:第2/50页 上一页 1 2 3 4 5 下一页 跳到 [ ] 页 [GO] */ public static function split5($allItemTotal, $currPageNum, $pageSize, $pageName='', $getParamList = array()){ if ($allItemTotal == 0) return ""; //页面名称 if ($pageName==''){ $url = $_SERVER['PHP_SELF']."?page="; $formUrl = $_SERVER['PHP_SELF']."?"; } else { $url = $pageName."?page="; $formUrl = $pageName."?"; } //参数 $urlParamStr = ""; foreach ($getParamList as $key => $val) { $urlParamStr .= "&". $key ."=". $val; } $formUrl .= $urlParamStr ."&page="; //计算总页数 $pagesNum = ceil($allItemTotal/$pageSize); //上一页显示 $prePage = ($currPageNum <= 1) ? "上一页" : "上一页"; //下一页显示 $nextPage = ($currPageNum >= $pagesNum) ? "下一页" : "下一页"; //按页显示 $listNums = ""; for ($i=($currPageNum-1); $i<($currPageNum+4); $i++) { if ($i < 1 || $i > $pagesNum) continue; if ($i == $currPageNum) $listNums.= " ".$i.""; else $listNums.= " ". $i .""; } $returnUrl = '第'.$currPageNum.'/'.$pagesNum.'页 '. $prePage ." ". $listNums ." ". $nextPage; $gotoForm = ' 跳到 '; return $returnUrl . $gotoForm; } } /* 例子: $allItemTotal = 1000; $currPageNum = isset($_GET['page']) ? $_GET['page'] : 1; $pageSize = 5; $pageName=''; $getParamList = array('classid'=>44); $pagination = new Pagination(); echo $pagination->split1($allItemTotal, $currPageNum, $pageSize, $pageName, $getParamList)."
"; echo $pagination->split2($allItemTotal, $currPageNum, $pageSize, $pageName, $getParamList)."
"; echo $pagination->split3($allItemTotal, $currPageNum, $pageSize, $pageName, $getParamList)."
"; echo $pagination->split4($allItemTotal, $currPageNum, $pageSize, $pageName, $getParamList)."
"; echo $pagination->split5($allItemTotal, $currPageNum, $pageSize, $pageName, $getParamList)."
"; */ ?>

人气教程排行