Welcome Guest, Not a member yet? Register   Sign In
Pagination not displaying results on next pages, can anybody help :-( [solved]
#1

[eluser]boltsabre[/eluser]
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]toopay[/eluser]
You missed
Code:
$config['uri_segment'] = 4;
at pagination config.
#3

[eluser]cideveloper[/eluser]
Boltsabre, Please do not double post in different sections.
#4

[eluser]boltsabre[/eluser]
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.
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB