Jump to content

Supplied argument is not a valid MySQL result resource


strago

Recommended Posts

$getURL = mysql_fetch_assoc(mysql_query("SELECT `urlname` FROM `workingurls` ORDER BY RAND() LIMIT 1"));

 

spits out

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /public_html/script.php on line 130

 

How do you make mysql_fetch_assoc a valid MySQL result resource?

You can't do that in one line. You have to RUN the query THEN get the results. In fact, it is best to create the query as a string, then run it, then get the results. That way, if there is a problem with the query you can echo the query to the page to identify any errors. I'm all for condensed/concise code, but this is not a good example.

 

 

$query = "SELECT `urlname` FROM `workingurls` ORDER BY RAND() LIMIT 1";
$result = mysql_query() or die("Query: $query<br>Error: " . mysql_error());
$getURL = mysql_fetch_assoc($result);

 

Also, ORDER BY RAND() is a bad solution. Google why and to get a better solution for getting a random value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.