我使用codeigniter并且我已经实现了分页,并且还在分页链接旁边显示了这样的消息
Displaying 1 to 11 of 11
但不知何故,如果行数较少,则会显示
Displaying -9 to 0 of 8
为什么显示负值?什么似乎导致这一个
以下是我为该
实施的代码$data['pagination_message'] = ' Displaying '.((($this->pagination->cur_page-1)*$this->pagination->per_page)+1).' to '.($this->pagination->cur_page*$this->pagination->per_page).' of '.$this->pagination->total_rows;
答案 0 :(得分:0)
将此分页与您的数据一起使用。这样可以正常工作
在控制器中
$count = $this->Model_Name->count();//get count of your product(s), can pass id too count($id)
//product pagination
$config['base_url'] = base_url() .'index.php/product_view/'.;
$config['total_rows'] = $count;
$config['per_page'] = 12;
$config['uri_segment'] = 2;
$limit = $config['per_page'];
// pagination style with boostrap.
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data['links'] = $this->pagination->create_links();
$data['product'] = $this->Model_Name->get_product($id,$limit,$page);//can pass without $id as well get_product($limit,$page)
在模型中
public function get_side_brand_product($limit,$page)
{
$query = $this->db->query("SELECT * FROM product WHERE product='$id' LIMIT $page, $limit");
$result = $query->result_array();
return $result;//this return data with objective array
}
在视图中(演示视图)
<div class="product_main">
<div class="product_inner">
<?php
foreach ($product as $new_product)
{
echo $new_product['field names'];
}
?>
</div>
<?php echo $links ?>//pagination
</div>