Can you tell me if I got this right? In plain English, "not a valid MySQL result resource" means, "I can't execute this line of code because something else is missing or wrong." That's kind of vague. Can it be made more specific?
Thanks!
| SitePoint Sponsor |





Can you tell me if I got this right? In plain English, "not a valid MySQL result resource" means, "I can't execute this line of code because something else is missing or wrong." That's kind of vague. Can it be made more specific?
Thanks!


yes, it can be much more specific
run it outside of php





I am not talking about a specific case, but trying to understand the warning in my head.


well, to begin with, it's a php error message
it is telling you that something is wrong with your mysql query, that it did not return a resource
i'm not really sure how it works, because i don't do php
and this is the mysql forum
![]()





That tells you how ignorant I am! I thought it had to do with queries, so this was the right place for the question.

the mysql_query() function returns a "resource" that holds the result of the query. expect that if the query results in an error, mysql_query() returns a boolean FALSE.
so let's say you have some code like this:
this query will obviously fail because i mis-spelled FROM as FORM. $result will therefore be a boolean FALSE. mysql_fetch_assoc() expects its first parameter to be a valid mysql resource. this is obviously not the case, hence the error.PHP Code:$result = mysql_query('select * form test_table');
$first_row = mysql_fetch_assoc($result);
Check out our new Industry News forum!
Keep up-to-date with the latest SP news in the Community Crier
I edit the SitePoint Podcast





That makes the terminology a little clearer. So far I have: The resource is the variable name we give for the query's result. The result is the contents of the resource, which result is generated erroneously by the query.
What's your explanation of the "supplied argument" in the error message?
Thanks!







Now it all comes together!
Sometimes I've seen this error on a WHILE statement, so it may cast a broader net.

You'll see this errors in lots of situations. Basically a mysql query returns an object, the "resource", you have to then use something like mysql_fetch_assoc() to parse the "resource" object into something that you can use. So whenever you see an error that mentions an invalid resource, that means either you didn't get a valid object, or php can't parse the object for some reason.




you can also troubleshoot your SQL with a PHP error by using die(mysql_error());
PHP Code:$sql = "QUERY";
$result = mysql_query($sql) or die(mysql_error());
No, I REALLY dislike having to use Joomla.





Crowden: Yes, I'm trying to use the troubleshooting as soon as I get an error. I've been reminded of this often enough on this blog!
Ditch182: Thanks, that was helpful.

It generally means your sql statement is incorrect.
Most often this is caused by a variable coming from PHP that didn't behave as expected.
$sql ="select thing from things where thing = '$some_thing' ";
The sample that crowden supplied:
... illustrates a good practice, because a) it obviously displays some kind of error ( which you may not want on your live sitePHP Code:$sql = "QUERY";
$result = mysql_query($sql) or die(mysql_error());
) but b) it gives you the opportunity to echo out $sql onto the page or log it.
Whereas this:
.. does not give you that opportunity.PHP Code:
$result = mysql_query($sql ="select thing from things where thing = '$some_thing' ";) or die(mysql_error());
There are lots of way of getting the sql into the light, but its probably generally true that many errors like this can be a mixture of PHP and sql errors.
Anyhow, get used to seeing them and work out a way of dealing with them because they will happen to you all the time, that way you hone in on where the error is coming from.
Bookmarks