调用例子:
$fenzhan_prize_order_db = pc_base::load_model('fenzhan_prize_order_model');
$page = max(intval($_REQUEST['page']), 1);
$pagesize = isset($_REQUEST['pagesize']) ? $_REQUEST['pagesize'] : 10;
$mydb =pc_base::load_model('mymodel');
$sql = "SELECT* FROM {$fenzhan_prize_order_db->get_tablename()} wherebiaoshi='" .$this->fenzhan[biaoshi]."'order by inputtime desc";
$mpages = $mydb->query_listinfo($sql,$page,$pagesize);
$mpages =$mydb->query_listinfo($sql,$page,$pagesize);
$msg =array();
$msg['returncode']= "0";
$msg['msg']= "文章";
$msg['comment']= $mpages;
echo JSON($msg);
分页方法:
public function query_listinfo(&$sql = '', $page = 1, $pagesize= 20, $setpages = 10,$array = array()) {
//取得记录总数$rs,计算总页数用
$array=$this->query_by_sql("SELECT count(1) as total FROM ( $sql) as a");
$total=$array[0]['total'];
//计算总页数
$pages=intval(intval($total)/$pagesize);
if ($total%$pagesize) {
$pages++;
}
//设置页数
if (isset($page)){
$page=intval($page);
}
else{
//设置为第一页
$page=1;
}1
//计算记录偏移量
$offset=$pagesize*($page - 1);
//读取指定记录数
$infos= $this->query_by_sql("$sql limit $offset,$pagesize");
$mpages =new mpages();
$mpages->page=$page;
$mpages->total=$total;
$mpages->pagesize=15;
$mpages->data=$infos;
return $mpages;