Php sql查询中的错误?

Php sql查询中的错误?,php,sql,Php,Sql,警告:mysql\u fetch\u assoc()希望参数1是资源,布尔值在第104行的C:\xampp\htdocs\阿森纳网站\ArsenalTables.php中给出 我有一个非常相似的查询,实际上它是相同的,不同的变量名可以工作,我不明白为什么它不工作 $customtable_query = "SELECT * FROM `arsenaltable`\n" . "ORDER BY `arsenaltable`.`points` DESC LIMIT 0, 30 "; $custom

警告:mysql\u fetch\u assoc()希望参数1是资源,布尔值在第104行的C:\xampp\htdocs\阿森纳网站\ArsenalTables.php中给出

我有一个非常相似的查询,实际上它是相同的,不同的变量名可以工作,我不明白为什么它不工作

$customtable_query = "SELECT * FROM `arsenaltable`\n" . "ORDER BY `arsenaltable`.`points` DESC LIMIT 0, 30 ";

$customtable_result = mysql_query($customtable_query);

while ($customtable_row = mysql_fetch_assoc($customtable_result))
{                   
    $played = $customtable_row['played'];
    echo $played;
}
  • 删除不必要的单引号(它们通常用于值而不是列名)
  • 删除换行符

    $customtable_query = "SELECT * FROM arsenaltable ORDER BY arsenaltable,points DESC LIMIT 0, 30 ";
    
    $customtable_result = mysql_query($customtable_query);
    
    while ($customtable_row = mysql_fetch_assoc($customtable_result)) {
    
        $played = $customtable_row['played'];
        echo $played;
    
    }
    
  • 希望这有帮助

    • 虽然与解决方案没有直接关系,但mysql_query已被弃用,最好改用mysqli_query(根据我的口味,PDO更好)

    您可能需要查看mysql_error()的具体错误。
    您的mysql\u query()调用返回false,这就是为什么错误会说mysql\u fetch\u assoc()中的参数是布尔值。

    还要在mysql\u query中传递连接变量。希望这有帮助

    $con=mysql_connect("localhost", "root","password");
    $customtable_query = "SELECT * FROM `arsenaltable`\n" . "ORDER BY `arsenaltable`.`points`    DESC LIMIT 0, 30 ";
    
    $customtable_result = mysql_query($customtable_query,$con);
    
    while ($customtable_row = mysql_fetch_assoc($customtable_result))
    {                   
    $played = $customtable_row['played'];
    echo $played;
    }
    

    为什么SQL查询中有换行符,而不是*explicit您的字段列表?这只是自找麻烦。对于调试,您最好在代码中放入
    mysql\u query()或die(mysql\u error())
    。为什么要在查询中添加“\n”?去掉这个。此外,mysql_*已被弃用,请改用mysqli_*或PDO。编辑:在你的表名和“订购人”后面加一个空格,我刚刚找到了!!我有2个Msql.close()忘记删除其他OneHanks,但是我仍然得到与前面相同的错误。布尔值为false有什么主要原因吗?我不确定,您的数据库是否确实包含表并填充了数据?您是否尝试直接在phpMyAdmin中运行查询并查看结果?尝试使用mysql_error()进行调试。另外-mysql\u查询已被弃用,请改用mysqli\u查询。我刚刚找到它!!我有两个Msql.close()忘记删除另一个