I';我在我们的项目中使用codeigniter框架进行分页,我想显示20个产品/页,但现在我可以显示1个产品/页


I'm working on pagination in our project using codeigniter framework,i want to display 20 products/page but now i can display 1product/page

我正在我们的项目中使用codeigniter框架进行分页,我想每页显示20个产品,但现在我可以每页显示1个产品。我尝试更改代码$config["per_page"]=1;到$config["per_page"]=20;但它显示的是1个产品/页,产品很少,而不是全部。我的代码低于

在我的查看页面:

<div class="container">        
      <?php  $chunkedArray  = array_chunk($results, 4);
       foreach($chunkedArray as $newRow) {
       echo ' <div class="row section">';?>
  <?php
    foreach ($newRow as $display) {
?>
          <div class="col-md-3 product-display">
              <a href="<?php echo base_url();?>index.php/productdisplay_controller/productImage?id=<?php echo $display->id; ?>">
              <img src="<?php echo 'data:image;base64,'.$display->product_image; ?>" class="img-responsive image" />
              </a>
        <div class="imgage-description">
            <a href="#" title="<?php echo $display->product_name; ?>"><b><p><?php echo $display->product_name; ?></p></b></a> 
                <div class="stitle"> 
                    <a data-p4plog="60491438452" data-domdot="id:2679,pid:60491438452,ext:'n=1|s=p|t={{attr target}}'" href="//gesac.en.alibaba.com/company_profile.html#top-nav-bar" target="_blank">eletronics pvt ltd</a>
                </div>
                <div class="pmo"> 
                    <div class="price"> <b class=""> US $1-1000 </b> / Piece </div> 
                    <div class="min-order"> <b>10 Pieces</b> (Min. Order) </div> 
                </div>
              <a href="<?php  echo base_url();?>index.php/welcome/contact"> 
                  <button class="desc-btn" title="Contact Supplier"><i class="fa fa-envelope"></i> Contact Supplier</button> 
              </a>
              </div>
          </div>
          <?php
    }?>
            <?php
    echo '</div> ';
}
    ?>
  </div>
     <div class="center">
    <ul class = "pagination">
    <?php foreach ($links as $link) {
echo "<li>". $link."</li>";
} ?>
</ul>
   </div> 

我的模型页面:

<?php
class homemodel extends CI_Model{
function __construct() {
parent::__construct();
}
public function record_count() {
return $this->db->count_all("product_sub_category3");
}

// Fetch data according to per_page limit.
public function fetch_data($limit, $id) {
$this->db->limit($limit);
$this->db->where('id', $id);
$query = $this->db->get("product_sub_category3");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
/*public function fetchData() {
  $query=$this->db->select('*');   
  $this->db->order_by('product_name','RANDOM');
  $this->db->from('product_sub_category3');
  $query = $this->db->get();
  return $query->result();
   } */
}
?>

在我的控制器中:

public function index()
    {
             $this->load->helper('url');
             $this->load->model('homemodel');
$config = array();
$config["base_url"] = base_url()."index.php/welcome/index";
$total_row = $this->homemodel->record_count();
$config["total_rows"] = $total_row;
$config["per_page"] =1;
$config['use_page_numbers'] = TRUE;
$config['num_links'] =2;
$config['cur_tag_open'] ='&nbsp;<a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->load->library('pagination');
$this->pagination->initialize($config);
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}
else{
$page = 1;
}
$data["results"] = $this->homemodel->fetch_data($config["per_page"], $page);
$str_links = $this->pagination->create_links();
$data["links"] = explode('&nbsp;',$str_links );
// View data according to array.
$this->load->view("home", $data);                  
    }
$str_links = $this->pagination->create_links();
$data['links'] = $str_links;

在您看来,只需执行echo $links;即可。

让我知道它是否有效。

我认为您需要给出偏移量和获取记录的限制。

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

并移除该线路$this->db->where('id', $id);

$offset将决定从哪个点获取下一条记录。例如:1-20、21-40等