Smudly Posted June 10, 2010 Share Posted June 10, 2010 Hi, I am creating a script that will go through a list of websites in my database, and randomly choose one as long as it meets these requirements: websites.active = y users.credits > 0 Here is the code I have come up with. Any suggestions would be helpful. // Select a Random Website $sitequery = "SELECT users.id, users.credits, users.username, websites.id, websites.url, websites.userid, websites.active FROM users INNER JOIN websites ON websites.userid = users.id where websites.active='y' and users.credits > 0 and websites.userid !=".$id." order by rand()"; $siteresult = mysql_query($sitequery) or die("Error in query: $sitequery. " . mysql_error()); if (mysql_num_rows($siteresult) != 0){ $siterow = mysql_fetch_array($siteresult); $url = $siterow["url"]; } I am getting the following error: Error in query: SELECT users.id, users.credits, users.username, websites.id, websites.url, websites.userid, websites.active FROM users INNER JOIN websites ON websites.userid = users.id where websites.active='y' and users.credits > 0 and websites.userid != order by rand(). You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by rand()' at line 3 Link to comment https://forums.phpfreaks.com/topic/204350-show-random-website-errors-help/ Share on other sites More sharing options...
MatthewJ Posted June 10, 2010 Share Posted June 10, 2010 and websites.userid != order by rand() You're missing something between != and orderby Link to comment https://forums.phpfreaks.com/topic/204350-show-random-website-errors-help/#findComment-1070191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.