Jump to content

Show Random Website errors, HELP!


Smudly

Recommended Posts

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

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.