从爆炸中获取 field1 中的前两个(切片?)并在 field2 中进行计数
myTable
field1 | field2
------------------------
47 | 46,43,22,88,99,12
22 | 12,99
88 | 77
12 | 99,22,84,5
我希望使用 PHP 从我的数据库(Mysql 5.x)中提取 field1 中在 field2 中具有最多值的 2 个值。如果重要的话,这是针对 Joomla/JomSocial 的,但我们非常感谢您的回复。
The out put of the following query should be
Top Member ID = 47
Top Member ID = 12
我已经尝试过,但没有任何反应:
$query = 'SELECT * FROM myTable;
$db->setQuery( $query );
$row = $db->loadObjectList();
$counted = array_count_values($row[field2]);
arsort($counted);
$top_two = array_slice($counted, 0, 2);
foreach ( $top_two as $data )
{
echo "Top Member ID = " . $data ."<BR />";
}
非常感谢
myTable
field1 | field2
------------------------
47 | 46,43,22,88,99,12
22 | 12,99
88 | 77
12 | 99,22,84,5
Using PHP am looking to pull from my db (Mysql 5.x) the 2 values from field1 that have the most values in field2. this is for Joomla/JomSocial if it matters but any reply is greatly appreciated.
The out put of the following query should be
Top Member ID = 47
Top Member ID = 12
I have tried this but nothing happend:
$query = 'SELECT * FROM myTable;
$db->setQuery( $query );
$row = $db->loadObjectList();
$counted = array_count_values($row[field2]);
arsort($counted);
$top_two = array_slice($counted, 0, 2);
foreach ( $top_two as $data )
{
echo "Top Member ID = " . $data ."<BR />";
}
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以直接使用 SQL 执行此操作:
返回的 2 行将是您想要的行。
You can do this in straight SQL:
The 2 rows returned will be the ones you want.