Welcome Guest, Not a member yet? Register   Sign In
Counting comments for blogitem
#11

[eluser]Rein Van Oyen[/eluser]
That's it! Altough, it seems the $count_entries returns a number that is 1 higher then it should. So I get an "undefined offset" error. What's wrong here, do I just need to do something like this:
Code:
$count_entries = count($query_blog)-1;

I think that's not really handy to do everytime I run code simular to this. Any idea's?

This is my blogmodel:
Code:
function get_entries($limit='') /* gets a list of blogitems, limit can be specified */
    {
    
        if(empty($limit)){
            $this->db->select('*')->from('blog_entries')->order_by('entry_id','desc');
        }
        else
        {
            $this->db->select('*')->from('blog_entries')->order_by('entry_id','desc')->limit($limit);
        }
        
        $query = $this->db->get();
        
        if($query->num_rows()>0)
        {
            $blog_array = array();
            foreach($query->result_array() as $row)
            {
                $blog_array['id'][]         = $row['entry_id'];
                $blog_array['date'][]         = $row['entry_date'];
                $blog_array['title'][]         = $row['entry_title'];
                $blog_array['body'][]         = $row['entry_body'];
                $blog_array['comments'][]     = $this->commentmodel->count_comments('blog_entry', $row['entry_id']);
            }
        }
        
        return $blog_array;
    }

You've been a great help so far, step by step I begin to understand the framework. (yes, datamodels are still kinda hard, but I'll get there eventually) Thank you!
#12

[eluser]LuckyFella73[/eluser]
Ahh sorry! It was my mistake.

Code:
// that should work
$count_entries = count($query_blog['id']);

The wrong line did count the number of indexes you set up with
the array (id,date,title,body,comments) - so you would get a count of 5
everytime regardless how many blog entries you have ...
#13

[eluser]Rein Van Oyen[/eluser]
Thank you! That works like a charm!




Theme © iAndrew 2016 - Forum software by © MyBB