strago Posted April 25, 2011 Share Posted April 25, 2011 $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 https://forums.phpfreaks.com/topic/234709-supplied-argument-is-not-a-valid-mysql-result-resource/ Share on other sites More sharing options...
Psycho Posted April 25, 2011 Share Posted April 25, 2011 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 https://forums.phpfreaks.com/topic/234709-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-1206134 Share on other sites More sharing options...
fugix Posted April 26, 2011 Share Posted April 26, 2011 yes you need at least 2 lines to accomplish this...run your query and then gather your array to take out the values that you want Link to comment https://forums.phpfreaks.com/topic/234709-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-1206202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.