Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count total number of rows of table in Cakephp

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?

like image 299
Patrick Avatar asked Nov 27 '13 04:11

Patrick


2 Answers

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')));
like image 124
Ma'moon Al-Akash Avatar answered Oct 20 '22 00:10

Ma'moon Al-Akash


you also try this with condition

$rowcount = $this->Product->find('count', array('conditions' => array('Product.fieldName' => 'value')
like image 45
Vipul Avatar answered Oct 19 '22 22:10

Vipul