我有一个服务器列表,首先我想要大多数在线用户订购服务器,
但是如果目前有一台服务器正在进行中+目前大多数玩家在线,我想忽略它。
基本上按PLAYERS COUNT + status =可用,但它不起作用?
$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;
}
为什么不显示所有可用的服务器+顶部玩家最多?
现在,我的表格显示了这一点:
img http://gyazo.com/e30bd07841cdec90e6854c55baddaf9e.png;
我做错了什么?
答案 0 :(得分:1)
你的where子句可能是select * from argonite_servers where server_status = 'Available' order by server_players desc;
看起来你已经在方法调用中合并了order
和criteria
子句,而不是将它们分开。
所以而不是
$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");