我的BLOG开张了,做好准备喔!!!
php adodb smarty 分页类
上一篇 /
下一篇 2008-04-11 15:22:49
/ 个人分类:技术文章
<?php
#adodb 数据库分页类
#yangzhu 2008-4-11
#数据调用方式
#$list=new show_class('select * from fivip_archives16',$db,'show_page.class.php',$_GET['page'],10);
#$db为adodb连接 url 可以跟参数 如show_page.class.php?id=123 最后为每页显示数量 $_GET['page']为当前页面
#link返回为html代码div id为page_nav 在页面中加载css即可 也可以进行修改为内容加效果
#www.3736.net 76vport team yangzhu 2008-4-11 show_page.class.php
class show_class{
public $sql;
Public $page;//当前页码从URL处链接过来
Public $evepage;//每页显示数据
Public $prepage;//前一页
Public $nextpage;//下一页
Public $countpage;//总页数
public $url; //当前调用地址
public $db; //adodb实便名
function __construct($sql, $db, $url, $page=1, $evepage=10){
$this->sql = $sql;
$this->url = $url;
$this->page = $page;
$this->evepage = $evepage;
$this->db = $db;
$this->getcount();
}
function getcount(){
$nums = $this->db->execute($this->sql);
$this->countpage = ceil($nums->recordcount()/$this->evepage);
}
function getarr(){
if ( $this->page == '' or $this->page < 1 ) $this->page = 1;
if ( $this->page > $this->countpage ) $this->page = $this->countpage;
$start = ($this->page - 1) * $this->evepage;
$this->sql.=" limit $start, $this->evepage";
$resarr = $this->db->getall($this->sql);
return $resarr;
}
function get_navlink(){
$this->prepage = $this->page - 1;
$this->nextpage = $this->page + 1;
if(strstr($this->url,"?")){
$symbol = '&';//连接符
} else {
$symbol = '?';
}
$link = "<div id=page_nav><a href=".$this->url.">首页</a> ";
if($this->prepage >= 1){
$link.=" <a href=".$this->url.$symbol."page=".$this->prepage.">前一页</a> ";
}
$link.=" 共".$this->page."/".$this->countpage."页 ";
if($this->prepage < $this->countpage-1){
$link.=" <a href=".$this->url.$symbol."page=".$this->nextpage.">后一页</a> ";
}
$link.="<a href=".$this->url.$symbol."page=".$this->countpage.">尾页</a> </div>";
return $link;
}
}
/*adodb调用部分 如果为在外部调用本类则不需要此部分*/
require_once('../changedb/adodba/adodb.inc.php');
$db = newadoconnection('mysql');
$host="localhost";
$user="root";
$pwd="root";
$database="dede";
$db->Connect($host, $user, $pwd, $database);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$db->Query("Set Names 'gb2312'");//
//$db->debug='true';
/*adodb调用结束*/
/*分页类调用*/
$list=new show_class('select * from fivip_archives16',$db,'show_page.class.php',$_GET['page'],10);
print_r($list->getarr());
echo $list->get_navlink();
?>
花了两三个小时才写好的这个类。用的是adodb的数据库连接。感觉还是比较满意的。用在smarty里非常方便。有需要的朋友自便。
安全因素自已传入数据的时候注意。类里面没有考虑安全,当然只要你数据合理也没什么漏洞。
导入论坛
引用链接
收藏
分享给好友
推荐到圈子
管理
举报
TAG: