2014-02-26 97 views
2

我是codeigniter中的新成员,我工作在其分页功能上。但我面临的一个问题是,它在所有页面上显示相同的值。这里是我的代码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>&lsaquo; First"; 
     $config["first_link"] = "</li>"; 
     $config["last_link"] = "<li>Last &rsaquo;"; 
     $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

@kumar_v其实我尝试这个代码从一些ware参考 –

+0

@kumar_v它完成,谢谢,需要添加$ page @ function productcolor($ id = 0,$ page = 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; 

} 
相关问题