CodeIgniter Forums
** Help Needed * - Pagination Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: ** Help Needed * - Pagination Problem (/showthread.php?tid=32681)



** Help Needed * - Pagination Problem - El Forum - 07-31-2010

[eluser]Bainzy[/eluser]
Hi guys,

Being trying to add pagination into my forum script however i am running into some problems.

What i currently have is categories, and when you click on a category it sorts the database again depending on the category selected, this works via the uri->segment(3) method.

here is a example of the code i use, here is my topics model :

Code:
function getTopics($category)
    {
        $data = array();
        
    if ($category)
    {
       $this->db->select('*');
       $this->db->join('category', 'category.CategoryID = topics.CategoryID');
       $this->db->join('users', 'users.Username = topics.CreatedBy');
       $this->db->order_by('topics.TopicID', 'desc');
       $options = array('topics.CategoryID'=>$category, 'topics.Active'=>'1');
       $q = $this->db->get_where('topics', $options);
      
    }
    else
    {
       $this->db->select('*');
       $this->db->join('category', 'category.CategoryID = topics.CategoryID');
       $this->db->join('users', 'users.Username = topics.CreatedBy');
       $options = array('topics.Active'=>'1');
       $this->db->order_by('topics.TopicID', 'desc');
       $q = $this->db->get_where('topics', $options);
    }        
        if($q->num_rows() >0)
        {
            foreach ($q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        
        $q->free_result();
        return $data;
    } // End of getTopics

And here is my controller code :

Code:
function topics()
    {
        $data['category'] = $this->MCats->getCurrentCat($this->uri->segment(3));
        $data['topics'] = $this->MTopics->getTopics($this->uri->segment(3));
        
        $this->load->view('forums', $data);
    }


Now how would i go about adding pagination into this ? every time i try it does not work or does not work how it should Sad

Any help is appreciated here Smile

Regards
Chris


** Help Needed * - Pagination Problem - El Forum - 08-01-2010

[eluser]Jan_1[/eluser]
you might show your script with pagination-lines that does not work.


** Help Needed * - Pagination Problem - El Forum - 08-01-2010

[eluser]Bainzy[/eluser]
I have just added the pagination the same as it says in the codeingiter guideline.


** Help Needed * - Pagination Problem - El Forum - 08-01-2010

[eluser]umefarooq[/eluser]
if you are using uri segment 3 for category and topic they try to use segment 4 for your pagination will take uri segment by default which is i think 3

give in config segment 4 will work

$config['uri_segment'] = 4;