Author Topic: Help with getting comments count and article category in Codeigniter  (Read 1020 times)

0 Members and 1 Guest are viewing this topic.

Offline misheckTopic starter

  • Irregular
  • Posts: 43
  • Gender: Male
    • View Profile
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
Code: [Select]
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
Code: [Select]
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.

Offline mapleleaf

  • Enthusiast
  • Posts: 237
    • View Profile
Re: Help with getting comments count and article category in Codeigniter
« Reply #1 on: March 03, 2010, 10:59:24 PM »
I think you want the total comments per category.
Anyway it seems you just need a function in the modal for the query you want as you can't use the function that requires an id.
By the way the codeigniter forum is exellent.