[SOLVED] Query malfunctions when go from 3 field parameters

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

[SOLVED] Query malfunctions when go from 3 field parameters

Post by cdickson »

I am trying to display results drawing from 4 categories that are in my database. Currently I have 3 categories, and the results display correctly:

Code: Select all

$query_rsClothing = "SELECT * FROM Members WHERE cat_id1 = '213 OR 141 OR 183' OR cat_id2 = '213 OR 141 OR 183' OR cat_id3 = '213 OR 141 OR 183' ORDER BY member_name";
If I add one more category to the query, however, the results show only the category that I add, which in this case is "6":

Code: Select all

$query_rsClothing = "SELECT * FROM Members WHERE cat_id1 = '6 OR 213 OR 141 OR 183' OR cat_id2 = '6 OR 213 OR 141 OR 183' OR cat_id3 = '6 OR 213 OR 141 OR 183' ORDER BY member_name";
Am I limited to the number of "ORs" that I can put into a query? This really has me stumped since it seems so simple.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

SELECT * FROM `Members` WHERE `cat_id1` IN(213,141,183) OR `cat_id2` IN(213,141,183) OR `cat_id3` IN(213,141,183) ORDER BY `member_name`

IN()
cdickson
Forum Contributor
Posts: 120
Joined: Mon Apr 05, 2004 1:30 pm
Location: Michigan, USA

Post by cdickson »

Thanks, feyd. I knew it had to be easy.

But just so I understand, did my first syntax not work because of a limit on the number of "OR" operators a single command can handle?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

numbers will only match against numbers.. so your first was turning that whole thing into '6'
Post Reply