tags:

views:

44

answers:

2

I have the following query which searched an episode guide database for user inputted data:

$query = "SELECT * 
            FROM epguide 
           WHERE EpisodeTitle LIKE '%$trimmed%' 
              OR Synopsis LIKE '%$trimmed%' 
              OR Notes LIKE '%$trimmed%' 
        ORDER BY o";

This works OK, but when I add 'Series = '$ser' AND' it stops:

$query = "SELECT * 
            FROM epguide 
           WHERE Series = '$ser' 
             AND EpisodeTitle LIKE '%$trimmed%' 
              OR Synopsis LIKE '%$trimmed%' 
              OR Notes LIKE '%$trimmed%' 
        ORDER BY o";

It looks like it should work. What can I do to fix it?

+2  A: 

You're going to need to decide whether you mean

SELECT * FROM epguide WHERE (Series = '$ser' AND EpisodeTitle LIKE '%$trimmed%') OR Synopsis LIKE '%$trimmed%' OR Notes LIKE '%$trimmed%' ORDER BY o

or

SELECT * FROM epguide WHERE Series = '$ser' AND (EpisodeTitle LIKE '%$trimmed%' OR Synopsis LIKE '%$trimmed%' OR Notes LIKE '%$trimmed%') ORDER BY o

and modify the query appropriately.

Ignacio Vazquez-Abrams
+3  A: 

Use:

  SELECT * 
    FROM epguide 
   WHERE Series = '$ser' 
     AND (EpisodeTitle LIKE '%$trimmed%' 
          OR Synopsis LIKE '%$trimmed%' 
          OR Notes LIKE '%$trimmed%')
ORDER BY o

You need the brackets to separate/group statements within the WHERE clause.

OMG Ponies
Thanks, Just what I needed
Zack