Ahh, Pagination not displaying results :-( [SOLVED]

#1
[eluser]boltsabre[/eluser]
Oppps, sorry, I posted this in the wrong forum, and now it wont let me delete it (but I can edit it), my apologies people...

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:
- www.mydomain.com/visas/forum/general-topics

New URl when pagination link is clicked:
- www.mydomain.com/visas/forum/general-topics/10

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:
Code:
function general_topics($postID = null){
        // set up pagination
            $this->load->library('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
            $this->pagination->initialize($paginationConfig);
            
            
        // 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);    
        }else{
            $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


Code:
<?php if($forum_results){ ?>
            <table border="1px">
                <tr>
                    <th width="370px">Title</th>
                    <th width="130px">Author / Posted</th>
                    <th width="50px">Replies</th>
                </tr>
                
                &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();
            }else{
                echo "There are currently no posts in this forum topic";
            }
        ?&gt;

And finally the model
Code:
// 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;
            free_result();
        }
    }

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

#2
[eluser]cideveloper[/eluser]
The problem you are having here is www.mydomain.com/visas/forum/general-topics/10 is passing $postID = 10 to general_topics thus running your else statement and pulling up visas/visa-forum-single-post-view

You should not do it this way. Have one controller and if you must 2 functions. The first function pulls up the list with pagination, while the second pulls up each single post.
I prefer to have 2 controllers. The first pulls up the list with pagination, while the second pulls up each single post.

#3
[eluser]boltsabre[/eluser]
Ah yes, of course... sometimes I cannot see the forest through the trees! hehe. Thanks cideveloper, that's great!

#4
[eluser]InsiteFX[/eluser]
If this issue has been Solved! Please udate your Post Title with [SOLVED] so that everyone knows
Thank you

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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