A weird mysql_fetch_(assoc,array,object) error [duplicate]
Possible Duplicate:
php warning mysql_fetch_assoc
I have a weird problem 开发者_JAVA百科about my script. It returns always error for mysql_fetch_array or mysql_fetch_assoc. I have used mysql_fetch many times in my project and I checked for this error many times but I am blind about what is happening. Is there something wrong about my script?
My functions aim is learning the biggest value of specified mysql field.
Here is the function:
function nextIncrement($table,$field) {
$sql = mysql_query("SELECT '$field' FROM '$table' ORDER BY '$field' DESC LIMIT 0,1");
while($row = mysql_fetch_assoc($sql)) {
$next = $row[$field];
}
$next = (int)$next;
return $next;
}
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource ...
Most likely, your mysql_query()
returned false for some reason.
See the manual for a list of possible values that mysql_query()
can return.
Do a echo mysql_error();
to see what's wrong.
Check to see that the query actually succeeds before proceeding to fetch results.
There may be an error in your SQL statement, or maybe you don't have an open database connection?
精彩评论