• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pagination problem

#1
[eluser]Unknown[/eluser]
I can't get pagination to work quite right. The userguide wasn't as helpful with this, so I went off this site (http://godbit.com/article/pagination-with-code-igniter), but the article is a bit old.

It seems to be mostly working, but the created paging links don't show the right current page. It is always stuck on 1. Any ideas? Thanks.

controller
Code:
public function display()
    {
        $this->load->model('seed_model');
        $this->load->library('pagination');
        $config['base_url'] = 'http://localhost/mc/index.php/browse/display/' . $this->uri->segment(3) . '/';
        $config['num_links'] = 2;
        $config['total_rows'] = $this->seed_model->total();
        $config['per_page'] = 5;
        $this->pagination->initialize($config);
echo $this->seed_model->total() . '<br />';
echo $config['base_url'];
        
        $sort = $this->uri->segment(3);
        if ($sort == 'popular')
        {
            $data['seeds'] = $this->seed_model->get_seeds('views', 'desc', $config['per_page'], $this->uri->segment(4));
        }
        else if ($sort == 'newest')
        {
            $data['seeds'] = $this->seed_model->get_seeds('date', 'desc', $config['per_page'], $this->uri->segment(4));
        }
        else if ($sort == 'oldest')
        {
            $data['seeds'] = $this->seed_model->get_seeds('date', 'asc', $config['per_page'], $this->uri->segment(4));
        }
        else
        {
            $data['seeds'] = $this->seed_model->get_seeds('views', 'desc', $config['per_page'], $this->uri->segment(4));
        }
        $this->load->view('h_view');
        $this->load->view('browse_view', $data);
        $this->load->view('f_view');
    }

view
Code:
&lt;?php echo anchor('browse/display/popular', 'Popular') . '   '; ?&gt;
    &lt;?php echo anchor('browse/display/newest', 'Newest') . '   '; ?&gt;
    &lt;?php echo anchor('browse/display/oldest', 'Oldest') . '   '; ?&gt;

    <p>
        &lt;?php
            foreach ($seeds as $row)
            {
                echo anchor("seed/view/$row->seed", $row->seed) . '<br />';
                echo $row->desc . '<br />';
                echo $row->views . '<br />';
                $this->load->helper('date');
                $unix = mysql_to_unix($row->date);
                echo mdate("%Y/%m/%d", $unix) . '<br /><br />';
            }
        ?&gt;
    </p>
    <p>
        &lt;?php echo $this->pagination->create_links(); ?&gt;
    </p>

#2
[eluser]neckbone[/eluser]
I think you need to add:

Code:
$config['uri_segment'] = 4;

I believe the default is 3, but since you're passing an extra parameter (sort), the pagination link would be the fourth segment.

#3
[eluser]Unknown[/eluser]
You've saved my neckbone. It works perfectly now. Thanks Big Grin

#4
[eluser]neckbone[/eluser]
Glad I could help!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.