How to count how many rows a query to the database returned (Cake PHP)?

1
$this->Post->Comment->find
    ('all', array('conditions' => array('Comment.post_id' => $id)));

I make this query, how do I know if it returned 5, 7, 10 ... comments before displaying them in the view?

    
asked by anonymous 23.12.2014 / 00:09

2 answers

3

I suppose you're saving the result in a variable, right? Something like this:

$comentarios = $this->Post->Comment->find('all', array('conditions' => array('Comment.post_id' => $id)));

In this case, use the count function of php to get the quantity:

$quantidade = count($comentarios);
    
23.12.2014 / 01:03
1

Use find('count');

$count = $this->Post->Comment->find
    ('count', array('conditions' => array('Comment.post_id' => $id)));
    
23.12.2014 / 02:16