CodeIgniter Forums

Full Version: Ahh, Pagination not displaying results :-( [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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:

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

The problem you are having here is 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.

El Forum

Ah yes, of course... sometimes I cannot see the forest through the trees! hehe. Thanks cideveloper, that's great!

El Forum

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