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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.