arboles
arboles

Reputation: 1331

Error handling for a mysql_fetch_object(): supplied argument is not a valid MySQL result

My question is how to remove the error, message saying

mysql_fetch_object(): supplied argument is not a valid MySQL result.

I need to throw/catch this error, but not sure how to do this.

When this function has a result to return, it works properly.

It is just that when when the result returns null, it says supplied argument is not a valid mysql result.

So how do I remove this error, so when it doesn't have anything to return, instead of displaying mysql_fetch_object(): supplied argument is not a valid MySQL result, it shows the user what I want.

$posts = show_allgroupsposts1($myusers,5);
if (count($posts)){
do a bunch of stuff.
}else{
nothing to display.
}
?>

currently, it returns:

mysql_fetch_object(): supplied argument is not a valid MySQL result
nothing to display.

Upvotes: 0

Views: 263

Answers (2)

Ami
Ami

Reputation: 1254

You can ensure that it never reaches the statement if the result is invalid:

$result = mysql_query($sql) or die("Error");
$row = mysql_fetch_object($result);

Upvotes: 1

gcochard
gcochard

Reputation: 11744

You should check wither the result variable is false.

if($result)
    mysql_fetch_object();
else
    ...do nothing

Upvotes: 1

Related Questions