【问题标题】:codeigniter pagination display same value on all pagecodeigniter 分页在所有页面上显示相同的值
【发布时间】:2014-03-29 06:45:12
【问题描述】:

我是 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; 

【问题讨论】:

  • $page 是在哪里定义的?
  • @kumar_v 实际上我从一些商品参考中尝试了这段代码
  • @kumar_v 搞定了,谢谢,需要加$page@function productcolor($id=0,$page=0)

标签: php codeigniter pagination


【解决方案1】:

您需要为您的查询添加限制 像这样 在你的模型中

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; 

}

【讨论】:

    【解决方案2】:

    将配置更改为 $config['use_page_numbers'] = FALSE;

    【讨论】:

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