PDA

View Full Version : SQL Help - Searching from multiple usergroups


Nullifi3d
01-10-2006, 05:46 PM
$db->query_first("SELECT homepage AS url FROM user WHERE usergroupid = 5 || 6 || 7 || 9 ||12 AND homepage != '' AND lastpost > UNIX_TIMESTAMP(NOW())-86400 ORDER BY RAND() LIMIT 1");
The query above works only with 2 numbers in the usergroupid field (one OR). Once I move it up to 3 it fails to work correctly. How do I fix?

Spam.Diz
01-11-2006, 01:47 AM
Why is the limit 1 there? I thought that meant after getting one found stop. Remove the limit 1 and see what happens.

Nullifi3d
01-11-2006, 10:32 AM
The LIMIT 1 needs to be there. I only need one random homepage, but it selected (randomly) from several different usergroups.

calorie
01-11-2006, 10:43 AM
$db->query_first("SELECT homepage AS url FROM user WHERE usergroupid IN (5,6,7,9,12) AND homepage != '' AND lastpost > UNIX_TIMESTAMP(NOW())-86400 LIMIT 1");

Nullifi3d
01-12-2006, 03:28 PM
Thanks a bunch.