5

Ok, I followed the instructions in the example perfectly. Ultimately, pagination works, kind of.

I get all of the pages listed: 1 | 2 | > | Last. Etc.

The first one is active, like it should be. I did the querying correctly as well, because each link will result in the correct query.

However, when I click on number 2, it will show me the next set of products correctly, but it will display the pagination from the first page.

Whatever pagination button I click on, will return the main pagination set: 1 (selected) | 2 | > | Last. It never changes! I'm loosing my patience, can someone help?

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
willbeeler
  • 669
  • 1
  • 13
  • 25
  • 1
    Can you post your code for the pagination so we can get an idea as to what is going on. – Cory Mar 30 '10 at 20:37

3 Answers3

10

I think I might know whats going on. You need to tell the pagination library which segment of the URL holds the offset.

For example, if your URL is /products/browse/all/20, you need to tell CodeIgniter that the 4th segment holds the offset

$config['uri_segment'] = 4;

The default for the library is URL segment #3. If the offset in your URL is not in position 3 and you forget to tell the pagination library this, it will interpret the wrong segment as being the offset. This can lead to the kind of behaviour you describe above where the pagination does not appear to change.

Stephen Curran
  • 7,433
  • 2
  • 31
  • 22
  • You Did it! I didn't find that configuration in the documentation, but it made it work right!! WOOHOO! You rock. – willbeeler Apr 01 '10 at 16:49
  • 2
    Thats great. I only know it because I went through the same pain myself when I began using the pagination :-) I remember getting the same behaviour and wondering what the hell was going on. – Stephen Curran Apr 01 '10 at 19:59
1

I also came across same error and finally was able to fix it. Just thought to share the code script, may be someone will be able to use it.

=====> Controller

// Default function
function index()
{   
    // Display listing      
    $this->listing();           
}

function listing($argDataArr = array()) 
{   

    // Initialize pagination
    $pageArr['base_url']    = $this->config->item('categoryBeAction')."/listing";
    $pageArr['total_rows']  = 15; //assume
    $pageArr['per_page']    = 5; //assume
    //You need to tell the pagination library which segment of the URL holds the offset.        
    $pageArr['uri_segment']  = 4; //URL eg: http://localhost/myproject/index.php/backend/category/listing/5 
    $this->pagination->initialize($pageArr); 

    // Get list of categories
    // Create data array and pass data to get function
    $dataArr['limitRows']    = $pageArr['per_page'];
    $dataArr['limitOffset']  = $this->uri->segment(4); //the dynamic value from this segment will be used as offSet
    $viewArr['listArr'] = $this->category_model->get($dataArr);

    //rest of the code...

}   

======> Model

function get($argDataArr = array())
{   

    //Select the fields required
    $this->db->select('id, name, parent_id, status');
    $this->db->from($this->config->item('tbl_category','dbtables'));

    $this->db->where('parent_id', $parentId);   
    $this->db->limit($argDataArr['limitRows'], $argDataArr['limitOffset']); 
    $this->db->order_by("name", "asc");
        $query_result = $this->db->get(); 

    return  $query_result;
}

======> View page

            <!--  Pagination -->                    
            <tr> 
            <td align="right">
                <?php  echo $this->pagination->create_links(); ?>                           
            </td> 
            </tr>
0

Which example?

echo $this->pagination->create_links();

^^Is this in your view?

stormdrain
  • 7,915
  • 4
  • 37
  • 76