forumnz Posted January 25, 2008 Share Posted January 25, 2008 Heres my code which is supposed to select a random row from a db. <?php include('connectdb.php'); $result = mysql_query("SELECT * FROM fflists ORDER BY RAND () LIMIT 1"); while($row = mysql_fetch_array($result)) { $business_name = $row['business_name']; echo $business_name; } ?> And the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/www/vhosts/foodfinder.co.nz/httpdocs/rowtest.php on line 5 Thanks, Sam. Link to comment https://forums.phpfreaks.com/topic/87683-solved-mysql_fetch_array-error/ Share on other sites More sharing options...
freebsdntu Posted January 25, 2008 Share Posted January 25, 2008 I guess it means your resultset is empty,try to debug on that. By the way,is that all the code? If yes,you have to connect to your database first before any operations on it. Link to comment https://forums.phpfreaks.com/topic/87683-solved-mysql_fetch_array-error/#findComment-448515 Share on other sites More sharing options...
revraz Posted January 25, 2008 Share Posted January 25, 2008 $result = mysql_query("SELECT * FROM fflists ORDER BY RAND () LIMIT 1") or die (mysql_error()); Your query is failing, the error will show you why. Link to comment https://forums.phpfreaks.com/topic/87683-solved-mysql_fetch_array-error/#findComment-448516 Share on other sites More sharing options...
forumnz Posted January 25, 2008 Author Share Posted January 25, 2008 Here is the error: FUNCTION foodfinder.RAND does not exist What does it mean? Sam. Link to comment https://forums.phpfreaks.com/topic/87683-solved-mysql_fetch_array-error/#findComment-448518 Share on other sites More sharing options...
forumnz Posted January 25, 2008 Author Share Posted January 25, 2008 Should be RAND() not RAND () Thanks! Link to comment https://forums.phpfreaks.com/topic/87683-solved-mysql_fetch_array-error/#findComment-448521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.