【问题标题】:codeigniter pagination Numbers not displayed correclycodeigniter 分页数字未正确显示
【发布时间】:2012-08-30 03:27:07
【问题描述】:

Codeigniter 分页数字未正确显示在结果页面中。

请帮帮我。

/控制器页面代码/

  function search_all()
  {
    $this->load->view(‘prd’); 
  $config = array();
  $config[‘base_url’] =  base_url().’/product_search/search_all’;
  $config[“total_rows”] = $this->search_product_model->record_count();
    $config[“per_page”] = 8;
    $config[“uri_segment”] = 3;

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data[“results”] = $this->search_product_model->
    get_search($config[“per_page”], $page);
    $data[“links”] = $this->pagination->create_links();

    //$this->load->view(“example1”, $data);
  $this->load->view(‘asd’, $data);
  }

【问题讨论】:

  • 请显示您的控制器和您处理手头问题的视图。根据您目前的解释,我们无法为您提供帮助。
  • 您必须发布一些代码。我们在你的脑海中看不到!
  • /*模型页面代码*/ function get_search($limit, $start) { $match3 = $this->input->post('search3'); $this->db->like(‘颜色’,$match3); $match2 = $this->input->post('search2'); $this->db->like(‘type’,$match2); $query = $this->db->limit($limit, $start)->get(‘products’);返回$查询->结果(); } 公共函数 record_count() { return $this->db->count_all(“products”); }
  • /*查看页面代码*/ foreach($results as $data) {?> id ?> code ?> php } ?>

标签: codeigniter pagination


【解决方案1】:

在 record_count() 函数中将搜索键作为参数 //You got 2 na.??

然后代替 search_params 把你提供给 record_count() 的相同键

【讨论】:

    【解决方案2】:

    试试这个

     function search_all()
     {               
       $config[‘base_url’] =  base_url(’product_search/search_all’);
       $config[“total_rows”] = $this->search_product_model->record_count();//2 in your case
       $config[“per_page”] = 8;
       $config[“uri_segment”] = 3;
    
    $this->pagination->initialize($config);
    
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data[“results”] = $this->search_product_model->
    get_search($config[“per_page”], $page);
    $data[“links”] = $this->pagination->create_links();
    
    //$this->load->view(“example1”, $data);
    $this->load->view(‘asd’, $data);
    }
    

    在您的模型中:

     public function get_search($limit, $page)
    {
     //Add this...???
      $this->db->limit($limit, $page);  //or try $this->db->limit($page,$limit)
    
    }
    

    【讨论】:

    • public function get_search($config[“per_page”], $page) 解析错误:语法错误,意外'[',期待')'
    • search_product_model::record_count() 缺少参数 1
    • 未定义变量:search_params
    • @murai...你不应该复制我给出的所有东西。只需根据你的需要进行一些简单的编辑“EVEN”。
    【解决方案3】:

    我觉得这个有问题

      $config[“total_rows”] = $this->search_product_model->record_count();
    

    为此,您没有传递搜索键,这样它就会计算它包含的所有数据。如果您根据搜索键获得记录计数,那就没问题了。像这样

      $config[“total_rows”] = $this->search_product_model->record_count('//search parameters');
    

    在你的模型中:

    Public function record_count($search_params)
    {
       $this->db->where('product',$search_params);
       return $this->db->count_all(“products”);
    }
    

    您可以根据需要进行修改,例如将“color”、“type”传递给您的 record_count() 函数,并基于此,您建议获取“count_all”。我希望它对您有用

    【讨论】:

    • $config["total_rows"] = $this->search_product_model->record_count('');
    • 函数 record_count($search_params) { $this->db->where('products',$search_params);返回 $this->db->count_all("products"); }
    • 在我的搜索中显示了产品 1 条记录..但是显示了分页数 (1,2,3)..我把条件每页显示了 8 条记录..如何控制页码?
    • 表示你想像这样显示(1,2,3,4...)...??or (1,2)
    • 我希望搜索记录显示在8条记录上方,需要分页(1,2)这样..否则在搜索结果页面中显示8条记录以下,分页号不需要显示..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    相关资源
    最近更新 更多