• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need Help with Count...

#1
[eluser]HSKrustofsky[/eluser]
I would like to display the number of comments that have been posted within each link on my site. For example, my site displays a list of videos and a person selects a video, they are then redirected to the page displaying the video where there they can then comment. In the initial list I would like to display the number of comments for each video. The code below is what I got, but all that is being displayed is the number of comments for the first video on every video on the list.

Model:
Code:
function getCount() {
        
        $this->db->select('videos.*, count(comments.entry_id) as num_comments');
    $this->db->from('videos');
    $this->db->join('comments', 'comments.entry_id = videos.id');
    $this->db->group_by('videos.id');
    $query = $this->db->get();
    return $query->row();
        
    }

Controller:
Code:
function index() {
        
        $this->load->model('videos_model');
        $data['count'] = $this->videos_model->getCount();
        $this->load->view('videos', $data);
        
    }

View:
Code:
...
        <div class="totalComments">Comments: &lt;?php echo $count->num_comments; ?&gt;</div>
    ...

What should I do?


Messages In This Thread
Need Help with Count... - by El Forum - 11-29-2010, 10:20 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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