How to count the total number of rows of table and pass it to the variable? For example, I have product table and there are 10 products in it. I want to count all the rows and get the result 10 and pass it to the variable $rowcount. How can I do it?
use find('count')
For example:
$total = $this->Article->find('count');
If you want to use a condition in your query, then pass the conditions array, here is a sample code:
$pending = $this->Article->find('count', array('conditions' => array('Article.status' => 'pending')));
you also try this with condition
$rowcount = $this->Product->find('count', array('conditions' => array('Product.fieldName' => 'value')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With