Welcome Guest, Not a member yet? Register   Sign In
Problem with Pagination
#1

[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="&lt;?php echo base_url() . " alt="" />
            </div>
            
            <div class="gradient">
            </div>
            
        </div>
        
        <div class="meta">
            <h2><a href="&lt;?php echo site_url(); ?&gt;/id/&lt;?php echo $a['ID']; ?&gt;">&lt;?php echo $a['title']; ?&gt;</a></h2>
            <h5><small>Author:</small> <a href="&lt;?php echo site_url(); ?&gt;/profile/&lt;?php echo $a['username']; ?&gt;">&lt;?php echo $a['author']; ?&gt;</a></h5>
            <h5><small>Uploaded:</small> &lt;?php $timestamp = strtotime($a['timestamp']); $timestamp = date('F j, Y', $timestamp); echo $timestamp; ?&gt;</h5>
            <h5><small> &lt;?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:"; } ?&gt;</small> &lt;?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']; } ?&gt;</h5>
            <p><small>&lt;?php echo $a['description']; ?&gt;</small></p>
        </div>
    
    </div>
&lt;?php endforeach; ?&gt;
<div id="pagination">
    <ul>
        &lt;?php echo $this->pagination->create_links();?&gt;
    </ul>
</div>




Theme © iAndrew 2016 - Forum software by © MyBB