Page 1 of 1
mySQL WHERE with MULTIPLE AND's and 1 OR
Posted: Tue Jul 21, 2009 7:07 pm
by psychotomus
Code: Select all
$result = mysql_query("SELECT id FROM pvpchallenges WHERE ((userid='$userid' AND oppid='$usersid' AND mapid='$map->id' AND status='p') OR (userid='$usersid' AND oppid='$userid' AND mapid='$mapid' AND status='p'))") or die(mysql_error());
if(mysql_num_rows($result) == 0)
my statement wont work but I get no errors. all vars are fine. it will always execute my IF statement even after I insert it the first time.
Re: mySQL WHERE with MULTIPLE AND's and 1 OR
Posted: Tue Jul 21, 2009 7:26 pm
by requinix
What do you get if you actually echo out the query before it runs? Like
Code: Select all
$query = "SELECT id FROM pvpchallenges WHERE ((userid='$userid' AND oppid='$usersid' AND mapid='$map->id' AND status='p') OR (userid='$usersid' AND oppid='$userid' AND mapid='$mapid' AND status='p'))";
echo $query;
$result = mysql_query($query) or die(mysql_error());
Re: mySQL WHERE with MULTIPLE AND's and 1 OR
Posted: Tue Jul 21, 2009 8:32 pm
by psychotomus
hmm. i get
SELECT id FROM pvpchallenges WHERE ((userid='$userid' AND oppid='$usersid' AND mapid='$map->id' AND status='p') OR (userid='$usersid' AND oppid='$userid' AND mapid='$mapid' AND status='p'))
Re: mySQL WHERE with MULTIPLE AND's and 1 OR
Posted: Tue Jul 21, 2009 10:05 pm
by superdezign
Then that is a problem. Are you sure your variables are defined?
Re: mySQL WHERE with MULTIPLE AND's and 1 OR
Posted: Wed Jul 22, 2009 4:18 pm
by psychotomus
superdezign wrote:Then that is a problem. Are you sure your variables are defined?
100% sure. cause it inserts correct data into mySQL database if its 0 results which is always.
Re: mySQL WHERE with MULTIPLE AND's and 1 OR
Posted: Wed Jul 22, 2009 6:10 pm
by psychotomus
nvm. had wrong var name. lols ;]