Welcome Guest, Not a member yet? Register   Sign In
Output Count
#8

[eluser]HSKrustofsky[/eluser]
Did what you told me and now it's giving me the comments of every post for only 1 ID. I'm guessing the first(id of 1) one. I thought maybe I needed a foreach loop, but when I tried that, It gives me an error saying, something about trying to get something that is a non-object.

Here is what I got:

Model:
Code:
function getCount() {
        
        $this->db->select('videos.*, count(comments.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?

By the way, thank you very much for helping me out.I know I must be annoying, but this a learning experience for me.


Messages In This Thread
Output Count - by El Forum - 08-24-2010, 11:46 PM
Output Count - by El Forum - 08-25-2010, 12:13 AM
Output Count - by El Forum - 08-25-2010, 11:40 PM
Output Count - by El Forum - 08-25-2010, 11:53 PM
Output Count - by El Forum - 08-26-2010, 09:00 AM
Output Count - by El Forum - 08-26-2010, 05:59 PM
Output Count - by El Forum - 08-27-2010, 12:40 AM
Output Count - by El Forum - 08-27-2010, 06:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB