gpt4 book ai didi

mysql - CakePHP 1.3 : How to represent the following MySQL code with Count(*) AS Total

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:18 27 4
gpt4 key购买 nike

我需要帮助将以下 MySQL 代码转换为 CakePHP 查找函数

$users= mysql_query(
"SELECT country, COUNT(*) AS total FROM users
GROUP BY country
ORDER BY total DESC
LIMIT 15"
);

这是我目前拥有的 CakePHP 查找代码。但是,我缺少 COUNT(*) AS Total

$users= $this->User->find(
'all',
array(
'fields' => array(
'country'
),
'group' => 'country',
'order' => 'country DESC',
'limit' => 10
)
);

谢谢,

最佳答案

使用 find->count 来计算你的用户: http://book.cakephp.org/1.3/view/1020/find-count

并定期查找所有内容以获取您的用户信息。

$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'));

关于mysql - CakePHP 1.3 : How to represent the following MySQL code with Count(*) AS Total,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9069835/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com