分页codeigniter只是在下一页加载部分项目

时间:2015-10-26 09:18:59

标签: php codeigniter pagination

我在codeigniter中遇到问题,如果我点击下一页只是加载部分项目。示例如果第1页项目显示A,B,C,D,E,F在第2页项目显示为D,E,F,G,H,我应该是页面中的G,H,I,J,K,L 2我不知道我的代码中有什么问题。

此链接我的代码:http://pastebin.com/45fS2AiX

由于

2 个答案:

答案 0 :(得分:1)

这是您的代码的一部分

$data['categoryHead'] = $this->M_home->listCategory();
$this->load->view('frontend/template/header', $data);//line 2
$data['productsLast'] = $this->M_home->listProductLast();
$data['productsLast2'] = $this->M_home->listProductLast2();
$data['category'] = $this->M_home->listCategory();

$config['base_url'] = base_url().'categoryproduct/'.$this->session->userdata('sesi_id');
$config['total_rows'] = $this->M_home->listProductPerCategory_num_rows();
$config['per_page'] = 12;
$config['first_link']           = 'First';
$config['last_link']            = 'Last';
$config['next_link']            = 'Next';
$config['prev_link']            = 'Prev';
$config['use_page_numbers'] = TRUE;
  

第2行加载视图。因此,它会在呈现分页数据之前将视图作为命令加载。

在模型中

function listProductPerCategory($limit1,$limit2){

    $session =$this->session->userdata('sesi_id');
    $sql = "SELECT category.category, product.id, product.picture, product.name, product.part_no FROM product, category
            WHERE category.id=product.id_category AND product.id_category = '$session' ORDER BY product.part_no ASC  LIMIT $limit2, $limit1";

    $query = $this->db->query($sql);
    $result = $query->result_array();

    $count = count($result);
    if(empty($count)){

       return false;
    }
    else
    {
        return $result; 
    }    
}

//count
function listProductPerCategory_num_rows(){

    $session =$this->session->userdata('sesi_id');
    $sql = "SELECT category.category, product.id, product.picture, product.name, product.part_no FROM product, category
            WHERE category.id=product.id_category AND product.id_category = '$session'";

    $query = $this->db->query($sql);
    $result = $query->result_array();

    $count = count($result);

    return $count;    
}

答案 1 :(得分:0)

替换此代码:

$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

$page = $this->uri->segment(3) ? ($this->uri->segment(3) - 1) * $config['per_page'] : 0;