douzhaiyuan1731 2019-02-19 04:11
浏览 77

使用where子句时Codeigniter分页问题

Codeigniter pagination with the passing parameter to where clause links not working

Here is my Model

public function record_count($category) {

  return $this->db->where('sub_category_name',$category)->count_all_results("categories_item");

}

 public function fetch_departments($category,$limit, $start) {

  $this->db->limit($limit, $start);

 $query=$this->db->where('sub_category_name',$category)->get("categories_item");

 if ($query->num_rows() > 0) 
     {
         foreach ($query->result() as $row) 
            { 
                $data[] = $row;
            }
          return $data;
       }
    return false;
   }
//Here is Controller
public function categories_item()
    {
        $this->load->database();
        $this->load->library('pagination');
        $this->load->model('Home_model');
        $config = array();
        $config["base_url"] = base_url() . "Home/categories_item";
        $category=$this->uri->segment(3);
        $this->db->where('sub_category_name',$category);        
       $config['total_rows'] =  $this->db->get('categories_item')->num_rows();
       $config['use_page_numbers'] = TRUE;
       $config["per_page"] = 1;
       $config["uri_segment"] = 3;
       $this->pagination->initialize($config);
       $page = ($this->uri->segment(3)) ? ($this->uri->segment(3)) : 0;
       $data["link"] = $this->pagination->create_links();
      if( !$data["results"] = $this->Home_model->fetch_departments($category,$config["per_page"], $page))
       {
         error_reporting(1);
       }
     else
       {
          $this->load->view("category_item_list",$data);
       }
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建