Welcome Guest, Not a member yet? Register   Sign In
Very stuck
#1

[eluser]Bainzy[/eluser]
Hello,

I am currently very stuck with implimenting the Pagination library with my code.

I am developing a forum and at present i have everything working correctly, however i can no think of a way of adding pagination into my scripts.

What i have is the main forum listing, here you can see all the topics and various topic information, part of this information is the category that the topic is posted in, now if the user clicks this category the page is then sorted to only display topics in that category, here is a example of my "topics" controller :

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

Here is the MTopics Model sample code :

Code:
function get_listings($category)
    {
        $data = array();
        
    if ($category)
    {
       $this->db->select('*');
       $this->db->join('category', 'category.CategoryID = topics.CategoryID');
       $options = array('topics.CategoryID'=>$category);
       $this->db->order_by('TopicID', 'desc');
       $q = $this->db->get_where('topics', $options);
      
    }
    else
    {
       $this->db->select('*');
       $this->db->join('category', 'category.CategoryID = topics.CategoryID');
       $this->db->order_by('TopicID', 'desc');
       $q = $this->db->get('topics');
       $rowcount = $q->num_rows();
    }        
        if($q->num_rows() >0)
        {
            foreach ($q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        
        $q->free_result();
        return $data;
    }

and my view file is a simple foreach statement.

How can i go around implementing pagination on this ?

Regards
Chris


Messages In This Thread
Very stuck - by El Forum - 02-01-2010, 04:47 AM
Very stuck - by El Forum - 02-02-2010, 10:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB