[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:
<?php echo anchor('browse/display/popular', 'Popular') . ' '; ?>
<?php echo anchor('browse/display/newest', 'Newest') . ' '; ?>
<?php echo anchor('browse/display/oldest', 'Oldest') . ' '; ?>
<p>
<?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 />';
}
?>
</p>
<p>
<?php echo $this->pagination->create_links(); ?>
</p>