使用" ORDER BY count"时出错在查询中

时间:2014-03-28 15:45:51

标签: php mysql

我正在使用以下查询来显示一些信息:

$result = mysqli_query ($con,"SELECT * FROM files,members,member_group WHERE files.member_id = members.member_id AND members.member_id = member_group.member_id AND group_id='$id' ORDER BY count DESC ");

我的问题是当我遗漏ORDER BY count DESC时它工作正常但是当它在那里时我收到以下错误:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /proj/co600/project/repo/public_html/select_field3.php on line 227

Count是我的数据库中的一列,用于记录下载发布的次数。

2 个答案:

答案 0 :(得分:4)

count是一个聚合函数,所以你需要用反引号括起来。

要清楚地了解您的错误..您需要更改代码...

$result = mysqli_query ($con,"SELECT * FROM files,members,member_group WHERE files.member_id = members.member_id AND members.member_id = member_group.member_id AND group_id='$id' ORDER BY count DESC ");
if(!$result)
{
 die(mysqli_error($con));
}

答案 1 :(得分:-1)

您在表中使用MySQL保留关键字作为列名。

使用以下查询:

$result = mysqli_query ($con,"SELECT * FROM files,members,member_group WHERE files.member_id = members.member_id AND members.member_id = member_group.member_id AND group_id='$id' ORDER BY `count` DESC ");