Codeigniter 如果按字段nama订购,则无法显示所有项目
我在Codeigniter中有模型代码功能,如下所示,如果我按兰德排序,可以显示所有项目,但如果按字段名排序,如part_no,则不能显示所有项目,在下一页中,显示与第1页相同 模型 控制器 你必须明白这一点 在SQL LIMIT中,start是起始记录数,而不是起始页数 但从您传递给listProductPerCategory的是页码 所以从第1页到第2页,下一页只移动了一条记录,而不是12条记录 因此,您需要在函数listProductPerCategory中进行修复。不要忘记更改变量名,这可能会让您感到困惑,请更改$start->$page 所以你应该得到如下的结果Codeigniter 如果按字段nama订购,则无法显示所有项目,codeigniter,Codeigniter,我在Codeigniter中有模型代码功能,如下所示,如果我按兰德排序,可以显示所有项目,但如果按字段名排序,如part_no,则不能显示所有项目,在下一页中,显示与第1页相同 模型 控制器 你必须明白这一点 在SQL LIMIT中,start是起始记录数,而不是起始页数 但从您传递给listProductPerCategory的是页码 所以从第1页到第2页,下一页只移动了一条记录,而不是12条记录 因此,您需要在函数listProductPerCategory中进行修复。不要忘记更改变量名,这
function listProductPerCategory($id, $limit, $page){
if($page < 1){
$page = 1;
}
if($page > 1){
$start = $limit * $page;
}else{
$start = 0;
}
$this->db->select('
category.id, category.category, product.id, product.id_category,
product.name, product.picture, product.description, product.permalink, product.part_no
');
$this->db->join('category', 'product.id_category = category.id');
$this->db->where('product.id_category', $id);
$this->db->order_by('product.part_no');
$this->db->limit($limit, $start);
$query = $this->db->get($this->tableProduct);
return $query->result();
}
你必须明白这一点
在SQL LIMIT中,start是起始记录数,而不是起始页数
但从您传递给listProductPerCategory的是页码
所以从第1页到第2页,下一页只移动了一条记录,而不是12条记录
因此,您需要在函数listProductPerCategory中进行修复。不要忘记更改变量名,这可能会让您感到困惑,请更改$start->$page
所以你应该得到如下的结果
function listProductPerCategory($id, $limit, $page){
if($page < 1){
$page = 1;
}
if($page > 1){
$start = $limit * $page;
}else{
$start = 0;
}
$this->db->select('
category.id, category.category, product.id, product.id_category,
product.name, product.picture, product.description, product.permalink, product.part_no
');
$this->db->join('category', 'product.id_category = category.id');
$this->db->where('product.id_category', $id);
$this->db->order_by('product.part_no');
$this->db->limit($limit, $start);
$query = $this->db->get($this->tableProduct);
return $query->result();
}
控制器-
试试这个-
function listcategory($page = 0){
$id = $this->input->get('list');
$data['categoryHead'] = $this->M_home->listCategory();
$this->load->view('frontend/template/header', $data);
$data['productsLast'] = $this->M_home->listProductLast();
$data['productsLast2'] = $this->M_home->listProductLast2();
$data['category'] = $this->M_home->listCategory();
//paging
$config['base_url'] = base_url('categoryproduct'.'?'.http_build_query($_GET));
$config['total_rows'] = $this->M_home->listProductPerCategory_num_rows($id);
$config['per_page'] = $per_page = 12;
$config['num_links'] = 2;
$config['uri_segment'] = 3;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['page_query_string'] = TRUE;
//end paging
$this->pagination->initialize($config);
$data['paging'] = $this->pagination->create_links();
$data['page'] = $page;
// $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data['listCategory'] = $this->M_home->listProductPerCategory($id, $per_page, $page);
$this->load->view('frontend/category', $data);
$this->load->view('frontend/template/footer');
按条件订购在您的型号中是错误的
试试这个-
$this->order_by'title'、'ASC或DESC或RANDOM' 控制器-
试试这个-
function listcategory($page = 0){
$id = $this->input->get('list');
$data['categoryHead'] = $this->M_home->listCategory();
$this->load->view('frontend/template/header', $data);
$data['productsLast'] = $this->M_home->listProductLast();
$data['productsLast2'] = $this->M_home->listProductLast2();
$data['category'] = $this->M_home->listCategory();
//paging
$config['base_url'] = base_url('categoryproduct'.'?'.http_build_query($_GET));
$config['total_rows'] = $this->M_home->listProductPerCategory_num_rows($id);
$config['per_page'] = $per_page = 12;
$config['num_links'] = 2;
$config['uri_segment'] = 3;
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Prev';
$config['page_query_string'] = TRUE;
//end paging
$this->pagination->initialize($config);
$data['paging'] = $this->pagination->create_links();
$data['page'] = $page;
// $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data['listCategory'] = $this->M_home->listProductPerCategory($id, $per_page, $page);
$this->load->view('frontend/category', $data);
$this->load->view('frontend/template/footer');
按条件订购在您的型号中是错误的
试试这个-
$this->order_by'title'、'ASC或DESC或RANDOM' 如果我使用“ASC”或“DESC”产品显示第1页与下一页相同,但如果在第1页和下一页之间使用“随机”,则不同的产品显示如果我使用“ASC”或“DESC”产品显示第1页与下一页相同,但如果在第1页和下一页之间使用“随机”,则不同的产品显示