/** * 分页查询 * * @access public * @param mixed $page * @param int $list_num * @param int $type * @param bool $ajax * @param string $ajaxFunction * @return source */ public function findPage($page, $list_num = 20, $type = 1, $ajax = false, $ajaxFunction = '') { $list_num = $list_num > 0 ? (int) $list_num : 20; $sql = $this->sql; $this->sql['limit'] = ''; $alias = preg_replace('/.+\\s+as\\s+(\\w+)\\s*/', "\$1.", $this->sql['table']); if ($alias == $this->sql['table']) { $alias = ""; } if ($this->sql['group'] != '') { $this->sql['fields'] = $this->primary_key ? 'count(distinct(' . $alias . $this->primary_key . ')) as total' : 'count(*) as total'; } else { $this->sql['fields'] = $this->primary_key ? 'count(' . $alias . $this->primary_key . ') as total' : 'count(*) as total'; } $this->sql['order'] = ""; $this->sql['group'] = ""; $result = $this->query(); $total = isset($result[0]['total']) ? $result[0]['total'] : 0; $total_page = round(($total - 1) / $list_num) + 1; if ($page > $total_page) { $page = $total_page; } $option = array("total_nums" => $total, "pagesize" => $list_num, "plus" => 3, "page" => $page, "ajax" => $ajax, "ajaxFunction" => $ajaxFunction); $pageing = new Paging($option); $data['html'] = $pageing->show(5); $this->sql = $sql; $page = $page > 0 ? (int) $page : 1; $start_id = $list_num * ($page - 1); $this->sql['limit'] = "limit {$start_id}, {$list_num}"; $data['data'] = $this->query(); $data['page'] = array('total' => $total, 'totalPage' => $total_page, 'pageSize' => $list_num, 'page' => $page); return $data; }