douzhi2017
2014-03-28 15:45
浏览 157
已采纳

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

I'm using the following query to display some information:

$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 ");

My issue is it works fine when I leave out ORDER BY count DESC but when it is there I get the following error:

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 is a column in my database which records the number of times a publication is downloaded.

图片转代码服务由CSDN问答提供 功能建议

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

 <  code> $ 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”); \  n   
 
 

我的问题是,当我忽略 ORDER BY count DESC 时它工作正常但是当它在那里时我得到以下错误:

 警告:mysqli_fetch_array()要求参数1为mysqli_result,在第227行的/proj/co600/project/repo/public_html/select_field3.php中给出布尔值
    
 
 

Count是我数据库中的一列,用于记录下载出版物的次数。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dpjtn48868 2014-03-28 15:47
    已采纳

    count is an aggregate function, so you need to surround it with backticks.

    To get a clear cut picture of your error.. You need to change your code like..

    $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));
    }
    
    点赞 打赏 评论
  • dongmu1914 2014-03-28 15:58

    You are having MySQL reserved keyword as column name in table.

    Use Below query:

    $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 ");
    
    点赞 打赏 评论

相关推荐 更多相似问题