Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用特定武器获得杀戮最多的玩家[mysql]_Php_Mysql_Arrays_Sorting - Fatal编程技术网

Php 使用特定武器获得杀戮最多的玩家[mysql]

Php 使用特定武器获得杀戮最多的玩家[mysql],php,mysql,arrays,sorting,Php,Mysql,Arrays,Sorting,我试图从kills数据库中找到最好的杀手(大多数杀手)。 将$important的killerId放入一个数组中,并将其与其他killer进行比较。用武器找到最好的杀手。 我该怎么做 $array = array(); $index = 0; while($mData = $q->fetch_assoc()) { $index++;

我试图从kills数据库中找到最好的杀手(大多数杀手)。 将$important的killerId放入一个数组中,并将其与其他killer进行比较。用武器找到最好的杀手。 我该怎么做

            $array = array();
            $index = 0;
            while($mData = $q->fetch_assoc())
            {
                $index++;
                $arr = explode('with ', $mData['killText']);
                $unimportant = array(" (in paintball)", " (in event)");
                $important = str_replace($unimportant, "", $arr[1]);

                if(empty($important)) { $important = "Suicide"; }

                $array[$important]['Kills']++;
                $array[$important]['Gun'] = $important;

                $query2 = $mysql->query("SELECT * FROM `kills` WHERE `killText` LIKE '%$important%' AND `killerID` = '". $mData['killerID'] ."'") or die($mysql->error);
                while($kData = $query2->fetch_assoc())
                {
                    // put the killerId of $important into an array, and compare it with the rest of the killers. Find the best killer with the weapon $important
                }
            }

GROUP BY
将实现以下功能:

"SELECT killerID, COUNT(*) FROM kills WHERE killText LIKE '%$important%' GROUP BY killerID;"
您只需获取“killerID”,就可以获得武器杀戮次数最多的杀手
$important

$kData = $query2->fetch_assoc();
$kData['killerID'];

提示:将一个MySQL查询放入另一个查询结果的
循环中时,几乎总是需要了解
JOIN