PDA

View Full Version : Random members URL?


roundhost
01-27-2005, 06:34 PM
I am currently using the following code to retreive a random members URL:


$getnames = $DB_site->query("
SELECT
* FROM user
ORDER BY rand()
LIMIT 1
");

while($geturl = $DB_site->fetch_array($getnames))
{
if ($geturl[homepage] == null) {

$rnd_site = "<a href=\"http://www.roundhost.net\" target=\"blank\">http://www.roundhost.net</a>";

} else {

$rnd_site = "<a href=\"$geturl[homepage]\" target=\"blank\">$geturl[homepage]</a>";

}

}


However, i would like it so that it always gets a member that has a url, rather than changing it to point to roundhost if their url is empty...how could i do this? It should be easy but all my attempts have failed! :(

Thanks in advance,

RoundHost

sabret00the
01-27-2005, 06:39 PM
change
SELECT
* FROM user
ORDER BY rand()
LIMIT 1

to SELECT
* FROM user
WHERE homepage != NULL
ORDER BY rand()
LIMIT 1

roundhost
01-27-2005, 06:56 PM
Thats one of the things i tried before, it just doesnt show anything! (thanks anyway) :o

Andreas
01-27-2005, 07:28 PM
SELECT
* FROM user
WHERE homepage != ''
ORDER BY rand()
LIMIT 1

?

roundhost
01-27-2005, 08:41 PM
SELECT
* FROM user
WHERE homepage != ''
ORDER BY rand()
LIMIT 1

?

Yes! It worked :) Wow, i must have NULL disabled for mysql or something strange :p Thanks a bunch :)

Marco van Herwaarden
01-27-2005, 09:10 PM
HAve a look at the "NOT <=>" this is a NULL-save version of "NOT ="

If i remember right

Dean C
01-27-2005, 10:01 PM
Btw, no point in selecting * when you just want the homepage. Go easy on your server and save it pulling all those extra un-needed columns ;)