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;
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
627315
  • 49
  • 5
  • If you've solved the problem, then post an answer inside the answer area of this. Please don't place the solution inside the question – Taryn Jun 03 '15 at 18:17

1 Answers1

0

Use this pagination with your data's. this will work fine

In Controller

        $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)

In Model

  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
    }

In view(demo view)

<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>
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85