-1

我应用了分页,但它在一页上显示了整个结果,或者如果我在查询中使用 Limit 应用它,那么它在每一页上显示相同的 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(); ?>
4

1 回答 1

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); 
}
于 2013-05-21T10:42:52.633 回答