我应用了分页,但它在一个页面上显示整个结果,或者如果我将其应用于限制 在我的查询中,它在每个页面上显示相同的20个结果。
这是控制器文件:
public function hhh($offset = 0 )
{
$sql_query = "select username from valenth_user where banned=1 limit 0,20";
$query = $this->db->query($sql_query)->result_array();
$data["pages"]=$query;
$this->load->library("pagination");
$config = array();
$row = count($pages);
$config['base_url'] = base_url().'/test/hhh/';
$config['total_rows'] = 120;
$config['per_page'] = 20;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
//$data['pages'] = $this-db-get('valenth_user', 10, $offset);
$this-load-library("pagination");
$this-template-load('template/template','onlinee',$data);
//$data['pages'] = $this->db->get($query, 10, $offset);
$query = array_slice($query-result_array(),$rows,$config['per_page']);
}
这就是观点:
<?
$rows = count($pages);
foreach($pages AS $hhh)
{
$user = new user ($hhh['username'],'username');
$hhh['username'] = $user->makeLink();
echo $hhh['username']."<br>";
}
?> <?php echo $this-pagination-create_links(); ?>
答案 0 :(得分:0)
尝试这样
模型
public function get_users($limit,$offset)
{
$sql_query = "select username from valenth_user where banned=1 limit $limit,$offset";
return $this->db->query($sql_query)->result_array();
}
public function get_total_users_count()
{
$sql_query = "select username from valenth_user where banned=1 ";
$query = $this->db->query($sql_query);
return count($query->result_array());
}
控制器
public function hhh()
{
$offset = $this->uri->segment(3,0);
$limit = $this->uri->segment(4,20);
$this->mymodel->get_total_users_count();
$config['base_url'] = site_url('test/hhh');
$config['total_rows'] = $this->mymodel->get_total_users_count();
$config['per_page'] = 20;
$config['uri_segment'] = 3;
$this->load->library("pagination");
$this->pagination->initialize($config);
$data["pages"] = $this->mymodel->get_users($limit,$offset);
$data["links"] = $this->pagination->create_links();
$this->template->load('template/template','onlinee',$data);
}