2

Im using codeigniter and i've implemented pagination and also the message like this one beside the pagination links

Displaying 1 to 11 of 11

But somehow if the rows are lesser it displays

Displaying -9 to 0 of 8

Why is it displaying a negative value? What seems to be causing this one

Here is the code that i've implemented for that

$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;
4

1 回答 1

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'] = '&laquo';
        $config['prev_tag_open'] = '<li class="prev">';
        $config['prev_tag_close'] = '</li>';
        $config['next_link'] = '&raquo';
        $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>
于 2015-06-19T09:23:37.910 回答