您好,欢迎访问一九零五行业门户网

php分页类代码,可自定义参数php分页代码

class pagelink {
/* 分页显示参数设置 */private $db_table = ;private $db_table_field = ;//要显示的数据库中的字段 private $condition = ; //查询条件private $sort = ; //排序条件private $page_size = 0; //每页显示的记录数目 private $link_num = 0; //显示页码链接的数目 private $page = 1; //当前页码 private $records = 0; //表中记录总数 private $page_count = 0; //总页数 private $pagestring = ; //前后分页链接字符串 private $linkurl = ; //当前页面路径private $urlpara = ; //当前页面url参数private $linkurlnum = 1;/* * 自定义分页*/private $linkformat = ;/* 获取的数据 */
private $page_data = ;//从数据库中获取的数据,//$page_data为二维数组接收
private $dbhelper;
/* 变量定义部分 end *//* 函数定义(类方法) begin */
function __construct() {include_once 'dbhelper/dbhelper.php';//这是数据库操作类
$this->dbhelper = new dbhelper();}/*
* 设置分页信息 begin * @param $db_table 表 * @param $db_table_field 字段 * @param $condition 條件 * @param $sort 排序 * @param $page_size 顯示條數 * @param $link_num 數字鏈接數 * @param $url 頁面路徑 * @param $para url參數 */public function set($db_table, $db_table_field, $condition, $sort, $page_size, $link_num, $url, $para) {$this->db_table = $db_table;//表名 $this->db_table_field = $db_table_field; //字段数组, $this->condition = $condition; //排序条件$this->sort = $sort; //排序条件 //将要显示的字段名称 //写入该数组 /* db参数设置 end *//* 分页参数设置 begin */
$this->page_size = $page_size;//每页显示记录的数目 $this->link_num = $link_num;//显示翻页链接的数目 $this->linkurl = $url;$this->urlpara = $para;/* 分页参数设置 end */}/* 设置分页信息 end */
/* 获取分页链接数据 begin */
public function get() {
$page_data[0] = $this->pagestring;$page_data[1] = $this->page_data;return $page_data;}/* 获取分页链接数据 end */
/* 页码处理 begin */
private function set_page() {
if (isset($_request[page])) {$this->page = intval($_request[page]);} else {$this->page = 1;}}/* 页码处理 end */
/* 获取db中记录的数目 begin */
private function get_records() {
$this->records = $this->dbhelper->counts($this->db_table, $this->condition);}/* 获取db中记录的数目 end */
/* 建立翻页链接字符串 begin */
private function page_link() {
$checkpage = intval($this->page / $this->link_num);$startpage = 1;$stoppage = 1;if($checkpage == 0 && $this->page link_num){$startpage = 1;}$linkpage = ($this->link_num / 2);if($this->page > $linkpage){$startpage = $this->page - $linkpage;}if(($startpage+$this->link_num)>$this->page_count){$startpage = $this->page_count - $this->link_num + 1;}if($startpage$startpage = 1;}$stoppage = $startpage+($this->link_num - 1);if($stoppage> $this->page_count){$stoppage = $this->page_count;}$countstr = 共.$this->records.條記錄;$currstr = .$this->page./.$this->page_count.頁 ;$beginlink = linkurl.%22?page=1%22.%24this->urlpara.%22>首頁;$prelink = linkurl.%22?page=%22.(%24this->page%20-%201).%24this->urlpara.%22>上一頁;$nextlink = linkurl.%22?page=%22.(%24this->page%20+%201).%24this->urlpara.%22>下一頁;$noprelink = 上一頁;$nonextlink = 下一頁;$endlink = linkurl.%22?page=%22.%24this->page_count.%24this->urlpara.%22>尾頁;if($this->page > ($linkpage + 1) && $this->page_count > $this->link_num){$currpage .= linkurl.%22?page=1%22.%24this->urlpara.%22>1;}for($i=$startpage;$iif($i == $this->page){ $currpage .= .$i.;}else{$currpage .= linkurl.%22?page=%22.%24i.%24this->urlpara.%22>.$i.;}}if(($this->page_count - $this->page) > $linkpage && $this->page_count > $this->link_num){$currpage .= ...linkurl.%22?page=%22.%24this->page_count.%24this->urlpara.%22>.$this->page_count.;}$jumppage .= linkurlnum.' onmouseover=select(); size=1 maxlength=4 onkeyup=\this.value=this.value.replace(/\\d+/g,'');\> ;$jumppage .= linkurl.?page='+document.getelementbyid('page_text_.$this->linkurlnum.').value+'.$this->urlpara.'\ name='page_submit' value='go' />;$this->linkurlnum++;if(!empty($this->linkformat)){$templinkformat = $this->linkformat;$templinkformat = str_replace(總記錄, $countstr, $templinkformat);$templinkformat = str_replace(頁次, $currstr, $templinkformat);if($this->page_count > 1){$templinkformat = str_replace(首頁, $beginlink, $templinkformat);if($this->page > 1){$templinkformat = str_replace(上一頁, $prelink, $templinkformat);}else{$templinkformat = str_replace(上一頁, $noprelink, $templinkformat);}if($this->page page_count){$templinkformat = str_replace(下一頁, $nextlink, $templinkformat);}else{$templinkformat = str_replace(下一頁, $nonextlink, $templinkformat);}$templinkformat = str_replace(尾頁, $endlink, $templinkformat);$templinkformat = str_replace(分頁, $currpage, $templinkformat);$templinkformat = str_replace(跳轉, $jumppage, $templinkformat);}else{$templinkformat = str_replace(首頁, , $templinkformat);$templinkformat = str_replace(上一頁, , $templinkformat);$templinkformat = str_replace(下一頁, , $templinkformat);$templinkformat = str_replace(尾頁, , $templinkformat);$templinkformat = str_replace(分頁, , $templinkformat);$templinkformat = str_replace(跳轉, , $templinkformat);}}
$this->pagestring.=$countstr. .$currstr;if($this->page_count > 1){$this->pagestring.=$beginlink;if($this->page > 1){$this->pagestring.=$prelink;}$this->pagestring.=$currpage;if($this->page page_count){$this->pagestring.=$nextlink;}$this->pagestring.=$endlink.$jumppage;}}/* 建立翻页链接字符串 end */
/* 获取数据 begin */
private function fetch_data() {
if ($this->records) {$limit = ($this->page - 1) * $this->page_size . ,$this->page_size;$this->page_data = $this->dbhelper->fetch($this->db_table, $this->condition, $this->sort, $limit);}}/* 获取数据 end */
/* 建立分页 begin */
public function create_page() {
$this->set_page();$this->get_records();$this->page_count = ceil($this->records / $this->page_size);$this->page_link();$this->fetch_data();}/* 建立分页 end */
function __destruct() {
}
/* 函数定义(类方法) end */
}/* 调用方法 include_once 'pagelink.php'; $pagelink = new pagelink(); //实例化对象 $pagelink->set(table, *(或字段), 条件, 排序, 数据条数, 每页链接数, 页面(list.php), 除?page=1外的其他参数(&id=1&name=test));//传入参数 $pagelink->create_page();//创建分页 $list = $pagelink->get();//获得数据 echo $list[0];//分页链接 print_r($list[1]); //打印出数据,或按你的需要循环出来*/
复制代码
其它类似信息

推荐信息