我是codeigniter的新手,我正在处理它的分页功能。但我面临一个问题,它在所有页面上显示相同的值。这是我的代码
控制器
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/dashboard/productcolor/'.$id;
$config["total_rows"] = $this->mdashboard->getAllcolorIDCount($id);
$config["full_tag_open"] = "<ul class='pagination'>";
$config["full_tag_close"] = "</ul>";
$config["num_tag_open"] = "<li>";
$config["num_tag_close"] = "</li>";
$config["cur_tag_open"] = "<li class='active'>";
$config["cur_tag_close"] = "</li>";
$config["prev_tag_open"] = "<li class='prev'>";
$config["prev_tag_close"] = "</li>";
$config["next_tag_open"] = "<li class='next'>";
$config["next_tag_close"] = "</li>";
$config["first_link"] = "<li>‹ First";
$config["first_link"] = "</li>";
$config["last_link"] = "<li>Last ›";
$config["last_link"] = "</li>";
$config['per_page'] = 2;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$data["totalpage"]=$config['per_page'];
$data['colorproduct'] = $this->mdashboard->GetAllcolorByPage($id,$config["per_page"], $page);
查看
<? echo $this->pagination->create_links();?></div>
模型
$data = array();
$Q = $this->db->select('*,(select pname from tbl_product where id=tbl_productcolor.pid)as productname,(select image from tbl_product where id=tbl_productcolor.pid)as image FROM tbl_productcolor where cid="'.$id.'" order by id asc ');
$Q = $this->db->get();
if ($Q->num_rows() > 0)
{
foreach ($Q->result_array() as $row)
{
$data[] = $row;
}
}
$Q->free_result();
return $data;
答案 0 :(得分:0)
您需要为查询添加限制 像这样 在你的模型中
function GetAllcolorByPage($id,$limit,$offset) {
$data = array();
$Q = $this->db->select('*,(select pname from tbl_product where id=tbl_productcolor.pid)as productname,(select image from tbl_product where id=tbl_productcolor.pid)as image FROM tbl_productcolor where cid="'.$id.'" LIMIT'. $offset.' , '. $limit .' order by id asc ');
$Q = $this->db->get();
if ($Q->num_rows() > 0)
{
foreach ($Q->result_array() as $row)
{
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
答案 1 :(得分:0)
将配置更改为 $config['use_page_numbers'] = FALSE;