Forum Moderators: open

Message Too Old, No Replies

MySQL Select Statment Question.

         

Modern Merlin

3:05 am on Sep 5, 2008 (gmt 0)

10+ Year Member



Ok so what I am trying to do is collect information from the database that goes like this.

$query = "SELECT * FROM table2 WHERE family = '".$familynum."' AND title = 'Capo' OR title = 'Soldier' OR title = 'Associates'" or die ("This is the family query error: ".mysql_error());

Lets say $familynum = 4

So basically I want the record if $familynum = 4 AND the title equals one of the three listed above.

However, with the code above it pulls it if one of the last three conditionals are correct. So even if $familynum doesnt = 4 its still displaying it if say title = soldier.

Im not sure what I am doing wrong here...

Any help would be greatly appreciated!

MM

phranque

4:21 am on Sep 5, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you weren't paying attention in high school algebra, were you?
=8)

try this:
$query = "SELECT * FROM table2 WHERE family = '".$familynum."' AND (title = 'Capo' OR title = 'Soldier' OR title = 'Associates')" or die ("This is the family query error: ".mysql_error());

Modern Merlin

8:40 am on Sep 5, 2008 (gmt 0)

10+ Year Member



LMAO! I knew there was a reason I had to take algebra over again!

OMG! LOL I found a couple of sites that said something about parenthesis but I couldn't figure out where they went. (They didn't give examples).

Thanks!