php利用模板分页程序(带demo演示);(1/3)_PHP教程
php教程利用模板分页程序(带demo演示);
这是一款比较经典的php分页代码哦,利用了程序模板,页面分离的方式来做这个文件分页功能,实在是太牛b了。
*/
//page.class.php
class page{
var $currentpage;
var $leftoffset;
var $rightoffset;
var $totalpage;//总页数
var $recordcount;//总记录数
var $pagesize;//每页显示条数
var $pageurl;
var $hypelink;
var $template;
var $tpl;
var $tagitems=array();
var $tagvalues=array();
var $sqlquery;
//构造函数
function page($currentpage=1,$pagesize=5,$leftoffset=2,$rightoffset=7,$pageurl="?page="){
echo "分页类开始";
$this->currentpage=ceil(abs(@$currentpage+0));
(empty($this->currentpage))?$this->currentpage=1:$this->currentpage=$this->currentpage;
$this->pagesize=ceil(abs(@$pagesize+0));
(empty($this->pagesize))?$this->pagesize=5:$this->pagesize=$this->pagesize;
$this->leftoffset=ceil(abs(@$leftoffset+0));
(empty($this->leftoffset))?$this->leftoffset=2:$this->leftoffset=$this->leftoffset;
$this->rightoffset=ceil(abs(@$rightoffset+0));
(empty($this->rightoffset))?$this->rightoffset=7:$this->rightoffset=$this->rightoffset;
$this->pageurl=$pageurl;
$this->setdefaulttagvalue();
}
//取得记录总数
//$sql="select count(id) as n from table";
function getrecordcount($sql,$conn){
$query=@mysql教程_query($sql,$conn);
if(!$query){echo "执行sql语句失败";exit();}
while($rs=mysql_fetch_row($query)){
$this->recordcount=$rs[0];//取得记录总数
}
$this->totalpage=ceil($this->recordcount / $this->pagesize);//计算总页数
if($this->currentpage > $this->totalpage){$this->currentpage=$this->totalpage;}//判断当前页是否大于总页数
mysql_free_result($query);
}
//select * from tb p->setlimit();
function setlimit(){
$limit="limit ".($this->currentpage-1)*$this->pagesize;
$limit.=",$this->pagesize";
return $limit;
}
function executesql($sql,$conn){
if(!$sql||!$conn){echo "参数传递错误";return false;}
$this->sqlquery=mysql_query($sql,$conn);
if(!$this->sqlquery){echo "执行sql语句失败";return false;}
}
function recordset(){
return mysql_fetch_array($this->sqlquery);
}
//取得模板内容
function gettemplate($filedir){
if(file_exists($filedir)){
$f=fopen($filedir,"r");
$this->template=fread($f,filesize($filedir));
}else{
echo "获取模板文件失败...文件不存在";
exit();
}
//取得区块内容
$start=strpos($this->template,"");
$end=strpos($this->template,"");
$this->tpl=substr($this->template,$start+strlen(""),$end-$start-strlen("")-2);
if($this->tpl==""){echo "模板内容为空,请检查标签设置是否正确。";exit();}
//echo $this->tpl;
}1 2 3
上一篇: phpinfo()10篇内容推荐
下一篇: 利用Java代码实现图片切割