1 2 3 下一页 参考自:/uploadfile/201212/7/64105936599.jpg" /> 主要是分页类的实现。 如上图文件结构所示,在library目录下新建Custom模块。各个文件的代码依次是: MySQL.php <?php require_once'Zend/Db/Adapter/Pdo/Mysql.php'; classCustom_Db_Adapter_Pdo_MysqlextendsZend_Db_Adapter_Pdo_Mysql { publicfunctionfatchPage($sql,$pagesize=20,$currentpage=1) { $currentpage=is_numeric($currentpage)?$currentpage:1; $result=array(); $result_array=$this->query($sql); $result['count']=count($result_array->fetchAll()); $result['pagecount']=$result['count']/$pagesize>1?ceil($result['count']/$pagesize):1; $offset=($currentpage-1)*$pagesize; $result['currentpage']=$currentpage; $result['firstpage']=1; $result['lastpage']=$result['pagecount']; $sql.=''.$this->select()->limit($pagesize,$offset)->__toString(); $result['table']=$this->query($sql)->fetchAll(); return$result; } } ?>
(责任编辑:admin) |