CakePHP 1.3:如何用Count(*)表示以下MySQL代码
我需要帮助将以下MySQL代码转换为CakePHP查找函数CakePHP 1.3:如何用Count(*)表示以下MySQL代码,mysql,cakephp,Mysql,Cakephp,我需要帮助将以下MySQL代码转换为CakePHP查找函数 $users= mysql_query( "SELECT country, COUNT(*) AS total FROM users GROUP BY country ORDER BY total DESC LIMIT 15" ); 这是我到目前为止的CakePHP查找代码。但是,我缺少作为总数的计数(*) $users= $this->User->find(
$users= mysql_query(
"SELECT country, COUNT(*) AS total FROM users
GROUP BY country
ORDER BY total DESC
LIMIT 15"
);
这是我到目前为止的CakePHP查找代码。但是,我缺少作为总数的计数(*)
$users= $this->User->find(
'all',
array(
'fields' => array(
'country'
),
'group' => 'country',
'order' => 'country DESC',
'limit' => 10
)
);
谢谢,使用查找->计数来计算您的用户数: 并定期查找所有内容以获取用户信息
$conditions = array("User.active" => 1);
$num_users = $this->User->find('count',array("conditions" => $conditions));
$users = $this->User->find('all',array("conditions" => $conditions));
$this->set(compact('users','num_users'));
使用“查找->计数”对用户进行计数: 并定期查找所有内容以获取用户信息
$conditions = array("User.active" => 1);
$num_users = $this->User->find('count',array("conditions" => $conditions));
$users = $this->User->find('all',array("conditions" => $conditions));
$this->set(compact('users','num_users'));