• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination number not changing

#1
[eluser]Unknown[/eluser]
Hi there, I'm having a tiny problem with my pagination of a forum

I am working on a threads area and paginating through them, I have been able to get pagination to work when I follow the pagination tutorial however this code has been written in the index()

This code does work and does display the new results when page 2 is clicked on, the problem is that the pagination links do not update to say that the user is on page 2 thus they are not able to return to page 1 also.

Here is the code I have

Controller
Code:
public function display_threads($category_id)
    {
        //Check if logged in
        if (! $this->tank_auth->is_logged_in())  
        {
             redirect('/auth/login/');
        }
        
        //get user data
        $data['user_data'] = $this->tank_auth->get_session_data();

        // implement pagination
        $this->load->library('pagination');
        $config['base_url'] = base_url().'/forum/display_threads/'.$category_id;
        $this->db->where('category_id', $category_id);
        $this->db->from('threads');
        $config['total_rows'] = $this->db->count_all_results();
        $config['per_page'] = '5';
        $config['full_tag_open'] = '<p>';
        $config['full_tag_close'] = '</p>';
    
        $this->pagination->initialize($config);
        // create breadcrumb trail
        $b = $this->create_breadcrumb_trail($category_id,'thread');
        $data['breadcrumb'] = $b[0]['category_name'];
        // load model
        $this->load->model('Forum_model');
        
        //do add thread if form submitted
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('title', 'Thread title', 'trim|required|xss_clean');
        $this->form_validation->set_rules('description', 'Thread text', 'trim|required|xss_clean');
        
        $data['validation_success'] = '';
        if ($this->form_validation->run() == TRUE) // validation went ok
        {
            $data['validation_success'] = '<span class="green">Congratulations on creating a new thread</span>';
            
            //$thread_data=array();
            $thread_data['category_id'] = $category_id;
            $thread_data['thread_title'] = $this->form_validation->set_value('title');
            $thread_data['thread_description'] = $this->form_validation->set_value('description');
            $thread_data['thread_datetime'] = date('Y-m-d h-i-m'); // uses the datetime format provided by mysql
            
            $this->Forum_model->add_new_thread($thread_data);
        }

        $data['thread_list'] = $this->Forum_model->get_all_threads($category_id,$config['per_page'],$this->uri->segment(4));
        
        // list all threads
        $data["dashboard_area"] = "forum";
        $this->load->view('main/header_dashboard',$data);
        $this->load->view('forum/list_forum_threads',$data);
        $this->load->view('main/footer');
    }

Model:
Code:
public function get_all_threads($category_id,$limit,$offset)
    {
        if(empty($offset))
            $offset = '';
        else
            $offset = ' OFFSET '.$offset;
            
        // uses an outer join
        $query = $this->db->query('SELECT t.*,
                                   DATE_FORMAT(t.thread_datetime,\'%d-%m-%Y , %h:%i %p\') as thread_datetime,
                                   ( SELECT count(*) FROM posts p WHERE p.thread_id = t.thread_id) as num_posts
                                   FROM threads t
                                   WHERE t.category_id = '.$category_id.'
                                   ORDER BY t.thread_datetime DESC
                                   LIMIT '.$limit.$offset);
        return $query->result();
    }

#2
[eluser]Twisted1919[/eluser]
Code:
$config['per_page'] = '5';
...
$config['uri_segment'] = 4;

#3
[eluser]Unknown[/eluser]
Oh dear :S

As simple as that.

Thanks alot Twisted


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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