Php 表中与Codeigniter活动记录具有相同值的记录的拉动计数
我在一个网站上工作,在那里我有一张桌子,上面摆着人们用特定诱饵钓到的鱼。lure_used类别是一个整数 我想找到用户最好的诱惑。因此,我想循环遍历所有用户捕获的行,并返回一个数组,其中包含每个诱饵以及使用了多少次 例如,我们可能有Php 表中与Codeigniter活动记录具有相同值的记录的拉动计数,php,mysql,database,codeigniter,activerecord,Php,Mysql,Database,Codeigniter,Activerecord,我在一个网站上工作,在那里我有一张桌子,上面摆着人们用特定诱饵钓到的鱼。lure_used类别是一个整数 我想找到用户最好的诱惑。因此,我想循环遍历所有用户捕获的行,并返回一个数组,其中包含每个诱饵以及使用了多少次 例如,我们可能有 catch_1 | lure_used = 5, catch_2 | lure_used = 3, catch_3 | lure_used = 6, catch_4 | lure_used = 3, 因此,我想知道5和6出现一次,而3出现两次。因此,3是最成功的诱
catch_1 | lure_used = 5,
catch_2 | lure_used = 3,
catch_3 | lure_used = 6,
catch_4 | lure_used = 3,
因此,我想知道5和6出现一次,而3出现两次。因此,3是最成功的诱饵
我知道我可能会在mysql查询中使用MAX,但我对它不是很熟悉,尝试也失败了
我已经能够创建一系列诱饵,如:
$lures = array(5, 3, 6, 3);
所以也许我可以循环通过它,然后输出像
5 = 1, 3 = 2, 6 = 1.
我想我是在抓救命稻草哈哈,有人对如何完成这件事有更好的想法吗
以下是“用户捕获”表中的所有字段:
'id' => $row->id,
'user_id' => $row->user_id,
'species' => $row->species,
'season' => $row->season,
'lure_used' => $row->lure_used,
'depth' => $row->depth,
'exact_depth' => $row->exact_depth,
'presentation' => $row->presentation,
'catch_weight' => $row->catch_weight,
'length' => $row->length,
'fishing_from' => $row->fishing_from,
'moon_phase' => $row->moon_phase,
'water_temp' => $row->water_temp,
'water_quality' => $row->water_quality,
'notes' => $row->notes,
'rod' => $row->rod,
'reel' => $row->reel,
'line' => $row->line,
'rig' => $row->rig,
'catch_image' => $row->catch_image,
'weather' => $row->weather,
'temp' => $row->temp,
'humidity' => $row->humidity,
'wind' => $row->wind,
'pressure' => $row->pressure,
'visibility' => $row->visibility,
'location' => $row->location,
'weather_icon' => $row->weather_icon,
'catch_date' => $row->catch_date,
实际的db模式会有帮助,但这并不是真的必要,我有一个带有表user_catch的数据库。表中使用了一个行lure_,类型为:integer并包含一个lure id。该表中的其他内容都不重要。它有30个不相关的字段,这会使问题复杂化。我喜欢人们问问题时告诉我回答问题需要知道什么。哈哈,好吧,我想我是个白痴。了解所有其他字段,如捕获日期、杆和卷轴定义。在这里帮助你。哈哈,我会把它贴在上面。
SELECT lure, count (*) as count
from user_catches
GROUP BY lures
ORDER BY count;