0

我有一个服务器列表,首先我想订购最多在线用户的服务器,

但是如果有一个服务器正在进行中+目前在线玩家最多,我想忽略它。

基本上按PLAYERS COUNT + status = available 排序,但它不起作用?

$query = $this->controller->db->fetch("argonite_servers", null, null, "server_status = 'Available', server_players");

这是我的方法:

    public function fetch($table, array $criteria = null, $limit = null, $order = null)
    {
        // The query base
        $query = "SELECT * FROM $table";
        
        // Start checking
        if ($criteria) {
            $query .= ' WHERE ' . implode(' AND ', array_map(function($column) {
                return "$column = ?";
            }, array_keys($criteria)));
        }
        
        // limit
        if ($limit) 
        {
            $query .= " LIMIT ". $limit;
        }
        
        //order
        if ($order)
        {       
            $query .= " ORDER BY ".$order." DESC";
        }
        
        $check = $this->pdo->prepare($query) or die('An error has occurred with the following message:' . $query);
        if ($criteria)
            $check->execute(array_values($criteria));
        else
            $check->execute();
        return $check;
    }

为什么它不会显示所有可用的服务器+顶部有最多玩家?

现在,我的表格显示了这一点:

图像
(来源:gyazo.com

我做错什么了?

4

1 回答 1

1

您可能是 where 子句select * from argonite_servers where server_status = 'Available' order by server_players desc; 看起来您已经在方法调用中合并了orderandcriteria子句,而不是将它们分开。

所以而不是

$query = $this->controller->db->fetch("argonite_servers", null, null, "server_status = 'Available', server_players");

你可能想要:

$query = $this->controller->db->fetch("argonite_servers", "server_status ='Available'", null, "server_players");

编辑:

要保持“可用”状态显示您很幸运,“可用”按字母顺序排序,请执行以下操作:

$query = $this->controller->db->fetch("argonite_servers", null, null, "server_status ASC, server_players");    
于 2013-07-28T19:00:19.137 回答