Page 1 of 1

Get banner if uid=something or nothing?!?

Posted: Wed Jun 11, 2008 5:05 am
by jmansa
I'm trying to make a rotating bannerscript where I want to get banners if the have the same id as the user and/or if the banner have no id (NULL)

Lets say my user have uid=1 and I have 3 banneres with the uid=1 and 2 banners with uid=NULL. Now I want to rotate all these 5 banners but am not shure how to?!?!

This is what I have tryid sofare:

Code: Select all

$uid = is_numeric($currClub['uid']) ?  $currClub['uid'] : '';
 
$num_displayed = 1 ;
 
$result = mysql_query ("SELECT * FROM sponsor WHERE (uid=".$uid." OR uid=NULL) AND sponsor_a=1 ORDER BY RAND() LIMIT $num_displayed"); 
 
while ($sponsor_a = mysql_fetch_array($result))
If i just enter WHERE uid=".$uid." I have no problem getting the banners with the uid=1 but I want to also get the banners with uid=NULL

Hope this make sense and somebody is able to help!

Re: Get banner if uid=something or nothing?!?

Posted: Wed Jun 11, 2008 5:32 am
by superdezign
In SQL, you don't write 'value = NULL', you write 'value IS NULL'. Null isn't a value, but rather the absence of a value, and must be treated specially.