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

时间:2014-04-04 13:35:56

标签: php mysql arrays sorting

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

            $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
                }
            }

1 个答案:

答案 0 :(得分:0)

GROUP BY可以解决问题:

"SELECT killerID, COUNT(*) FROM kills WHERE killText LIKE '%$important%' GROUP BY killerID;"

你只需获取“killerID”并获得杀手最多的杀手$important

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