MySQL Warning: Invalid Argument for mysql_fetch_assoc
Issue:
When attempting to retrieve data from a MySQL database, the following error message is encountered:
mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
Explanation:
The mysql_fetch_assoc() function is designed to extract a row from a MySQL result set. As its name suggests, it expects a valid result resource as an argument, which represents the link to the database search results. However, in this case, the argument passed to the function is not a valid result resource, triggering the error.
Solution:
To resolve this issue, ensure that the variable assigned to the result of your MySQL query is a valid result resource. Here's a breakdown of the code you provided:
$musicfiles = getmusicfiles($records['m_id']);
This line executes the getmusicfiles() function and assigns the result to the $musicfiles variable. Now, let's examine the getmusicfiles() function:
function getmusicfiles($m_id) {
$music = "select * from music WHERE itemid=".$s_id;
$result = getQuery($music, $l);
return $result;
}
This function executes a MySQL query, assigns the result to the $result variable, and then returns it. It's important to note that getQuery() is not shown in the provided code, so it's not possible to analyze if it's properly retrieving the result resource.
Once you have confirmed that getQuery() is returning a valid result resource, you should be able to successfully call mysql_fetch_assoc($musicfiles). Remember, the function expects a valid result resource as its argument, so ensure that it's available before calling mysql_fetch_assoc().
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3