looping through php table is not working [Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given]

后端 未结 1 861
终归单人心
终归单人心 2021-01-26 14:32

I am getting this error on my index.php page where i have also included the code


Warning: mysql_fetch_a

相关标签:
1条回答
  • 2021-01-26 15:27

    You have quoted your table name in single-quote characters, which MySQL interprets as a string literal. You should either use backticks, or no quote characters at all:

    $sql = "SELECT * FROM `menulinks`";
    

    This syntax error caused the mysql_query() function to return false, which you can test as follows:

    $result = mysql_query($sql) or die(mysql_error());
    

    Also note, as documented in a big red box at the top of the manual page for mysql_query():

    Suggested alternatives

    Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:

    • mysqli_query()
    • PDO::query()
    0 讨论(0)
提交回复
热议问题