[eluser]georgerobbo[/eluser]
I have a problem with pagination.
http://georgerobbo.dyndns.org/sharify/index.php/browse
As you can see from the pagination, when you click on two your taken to the first paginated page and the url segment /1 is concatenated onto the end of the url. You will now notice that you are unable to get back to the first page from the pagination.
How do I fix this?
My model, view, controller are:
Code:
<?php
class Post extends Model {
function Post()
{
parent::Model();
}
function get_all($limit = NULL, $offset = NULL)
{
$this->db->select('*');
$this->db->orderby('ID', 'Desc');
$this->db->limit($limit, $offset);
$query = $this->db->get('post');
return $query->result_array();
}
function count_posts()
{
return $this->db->count_all_results('post');
}
}
Code:
<?php
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function all()
{
$data['title'] = "Browse";
$data['meta']['random'] = mt_rand(1,4);
if(current_url() == site_url() . "/welcome/all")
{
redirect(site_url() . "/browse");
}
$this->load->library('pagination');
$config['base_url'] = site_url() . "/browse";
$config['total_rows'] = 2;
$config['per_page'] = 1;
$this->pagination->initialize($config);
$data['list'] = $this->Post->get_all($config['per_page'], $this->uri->segment(2));
foreach ($data['list'] as $a):
$id = $a['ID'];
endforeach;
if(isset($id)) {
$data['commentcount'] = $this->Post->count_comments($id);
}
$this->load->view('meta', $data);
$this->load->view('header', $data);
$this->load->view('archive', $data);
}
}
Code:
<?php foreach ($list as $a): ?>
<div class="panel">
<div class="item">
<div class="thumb">
<img src="<?php echo base_url() . " alt="" />
</div>
<div class="gradient">
</div>
</div>
<div class="meta">
<h2><a href="<?php echo site_url(); ?>/id/<?php echo $a['ID']; ?>"><?php echo $a['title']; ?></a></h2>
<h5><small>Author:</small> <a href="<?php echo site_url(); ?>/profile/<?php echo $a['username']; ?>"><?php echo $a['author']; ?></a></h5>
<h5><small>Uploaded:</small> <?php $timestamp = strtotime($a['timestamp']); $timestamp = date('F j, Y', $timestamp); echo $timestamp; ?></h5>
<h5><small> <?php if($meta['random'] == 1) { echo "Favourites:"; } elseif($meta['random'] == 2) { echo "Comments:"; } elseif($meta['random'] == 3) { echo "Views:"; } elseif ($meta['random'] == 4) { echo "Category:"; } ?></small> <?php if($meta['random'] == 1) { echo $a['favourites']; } elseif($meta['random'] == 2) { echo $commentcount; } elseif($meta['random'] == 3) { echo $a['views']; } elseif ($meta['random'] == 4) { echo $a['category']; } ?></h5>
<p><small><?php echo $a['description']; ?></small></p>
</div>
</div>
<?php endforeach; ?>
<div id="pagination">
<ul>
<?php echo $this->pagination->create_links();?>
</ul>
</div>