簡易 PHP MySQL 分頁類

2021-06-09 11:45:35 字數 1330 閱讀 1008

初學者一般都不太理解分頁的原理,因此常常為分頁發愁

paging.php

<?php

class paging

static function bar($tpl='')

echo $tpl;

}}

通常你都有類似這樣的語句

$sql =".....";

$rs = mysql_query($sql);

或$rs = mysql_query("select ....");

你只需改作

include 'paging.php';

$rs = paging::prepare($sql, 每頁行數);

在需要出現分頁條的地方寫入

paging::bar();

就可以了,非常簡單!

換一種呼叫寫法,可能感覺要好些

paging.php

class paging

public static function getinstance()

protected $count = 0;

protected $size = 0;

protected $page = 0;

function prepare($sql, $pagesize=10)

function bar($tpl='') 頁 第頁 首頁

尾頁';

$count = ceil($this->count / $this->size);

$page = $this->page;

$d = array(

'' => 1,

'' => $page > 1 ? $page - 1 : 1,

'' => $page < $count ? $page + 1 : $count,

'' => $count,

'' => $count,

'' => $page,

);foreach($d as $k=>&$v) ', '', '', '')))

}echo strtr($tpl, $d);

}}function mysql_paging_query($sql, $num=10)

function mysql_paging_bar($tpl='')

include 'paging.php';

$rs = mysql_paging_query($sql, 20);//替代 mysql_query

mysql_paging_bar();//顯示分頁條

php mysql 公共分頁類

pagesize 5 每頁條數 page page 1 1 page start page 1 pagesize 起始條數 資訊列表 menulist this conn getlist tb admin manager where,order by fid limit start,pagesize...

簡易分頁類

這是乙個簡單易用的分頁類。只需在你原有的程式中加兩句 改一句就可以了 先貼 paging.php php code phpclass paging static function bar tpl echo tpl 通常你都有類似這樣的語句 sql rs mysql query sql 或 rs my...

簡易分頁類

phpclass paging static function bar tpl echo tpl 通常你都有類似這樣的語句 sql rs mysql query sql 或 rs mysql query select 你只需改作 include paging.php rs paging prepar...