Jump to content

Help with getting comments count and article category in Codeigniter


misheck

Recommended Posts

I am stuck on completing my first CI website. I need to get the comment counts and article category on my homepage. I have functions already in my models that retrieves this information but they all need an id passed in the function in order to retrieve the correct information for the articles. So I can retrieve both the comment count and category in my article view but I cannot on the homepage because the homepage contains multiple articles from various categories. I dont what addittional information I can post here but I will post my homepage controller and the getcomments model . Homepage

function index()
    {
   
    $data['cats'] = $this->MCats->getTopCategories(); //we will replace soon!
    $data['title'] = "Shout-Africa";
    $data['main'] = 'public_home';
    $data['featured'] = $this->MPosts->getAllFeaturedPosts();
    $data['post'] = $this->MPosts->getAllActivePosts();
    $data['comms'] = $this->MComments->getLatestComments();     
    $this->load->vars($data);
    $this->load->view('newheader'); 
    $this->load->view('newnav'); 
    $this->load->view('newfeatured');    
    $this->load->view('newcontent');
    $this->load->view('newvideo');
    $this->load->view('newrightside');
    $this->load->view('newwidget');
    $this->load->view('footer');

    }

the getcomments model

function getComments($postid){
     $data = array();
     $this->db->where('post_id',$postid);
     $Q = $this->db->get('comments');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[] = $row;
       }
    }
    $Q->free_result();  
    return $data; 
}

Any help is appreciated.

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.