CodeIgniter Forums

Full Version: Pagination not displaying results on next pages, can anybody help :-( [solved]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hi guys, really hoping someone can help me with a pagination issue, I'm baffled.

So, I've got all the code in, it looks like it's working:
- when the view is first loaded I see the correct number of results as set in my paginationConfig variable.
- I see the pagination at the bottom, with the correct number of 'pages'
- When I click on the another page my url is changing to reflect the 'offset' for the databse/ model call (see below).
- But when I click on another 'page' I just see no results from my db - no error messages, just nothing...

Original URl when view loads:

New URl when pagination link is clicked:

If someone could look at my code and suggest where I have gone wrong I'd be extremely grateful, a million thanks in advance!!!

Controller code:
function general_topics($postID = null){
        // set up pagination
            $paginationConfig['base_url'] = base_url().'visas/forum/general-topics';
            $paginationConfig['total_rows'] = $this->db->get('visa-forum-general')->num_rows();
            $paginationConfig['per_page'] = 10;
            $paginationConfig['num_links'] = 10;
            //initialise it and pass in the config array above
        // postID defined in the link in visa-forum-single-post-view.php
        if ($postID == null){
            $this->data['forum_results'] = $this->visa_forum_model->getAllPosts('visa-forum-general', $paginationConfig['per_page'], $this->uri->segment(4));
            //For the link url in visa-forum-single-post-view.php
            $this->data['controllerFunctionName'] = 'general-topics';            
            $this->load->view('visas/visa-forum-view', $this->data);    
            $this->data['single_post'] = $this->visa_forum_model->getSinglePost('visa-forum-general');
            $this->data['single_post_replies'] = $this->visa_forum_model->getSinglePostReplies('visa-forum-general-replies', $postID);            
            $this->load->view('visas/visa-forum-single-post-view', $this->data);

The view code

<?php if($forum_results){ ?>
            <table border="1px">
                    <th width="370px">Title</th>
                    <th width="130px">Author / Posted</th>
                    <th width="50px">Replies</th>
                &lt;?php foreach ($forum_results as $row){
                    echo "<tr>";
                        echo "<td width='310px'>".anchor('visas/forum/'.$controllerFunctionName.'/'.($row->id).'/'.$row->seourl, $row->title)."</td>";
                        echo "<td width='100px'>".$row->author."<br/>".date("d/m/y h:i A", strtotime($row->posted))."</td>";
                        echo "<td width='50px'>".$row->reply_count."</td>";
                echo "</table>";
                echo $this->pagination->create_links();
                echo "There are currently no posts in this forum topic";

And finally the model
// this limit and offset are set in the controller in the pagination config array, needed to make pagination work
    function getAllPosts($tableName, $limit, $offset){
        $this->db->order_by("id", "desc");
        $q = $this->db->get($tableName, $limit, $offset);
        if($q->num_rows() >0 ){
            foreach($q->result() as $row){
                $data[] = $row;
            return $data;

Any help would be great, I've been stuck on this for hours now!!!

El Forum

You missed
$config['uri_segment'] = 4;
at pagination config.

El Forum

Boltsabre, Please do not double post in different sections.

El Forum

cideveloper, I had originally posted this in the forum 'General CodeIgniter Discussion (no code)' by mistake (it seems to default to that for some reason, it just happened with another post of mine - I'll try really hard to check that before my next post).

Anyway, I tried to delete my post in the wrong forum, but it wont let me - apparently I do not have the permissions to delete my own posts (say what.......???), and I then re-posted in the correct forum for those users in there who may find it helpful.

Long story short, it was unintentional, I wont do it again.

El Forum

NP. I forgot to check the timestamp. It does seem wierd that we cannot delete our own posts. :bug: