【问题标题】:Pagination with codeigniter not working properly使用 codeigniter 的分页无法正常工作
【发布时间】:2013-05-21 09:59:33
【问题描述】:

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

【问题讨论】:

  • 您没有将动态参数传递给您的查询,这就是它在每个页面上显示相同结果的原因

标签: php sql codeigniter pagination


【解决方案1】:

这样试试

型号

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); 
}

【讨论】:

    猜你喜欢
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多