Page 1 of 1

How to search multiple fields?

Posted: Sun Jul 25, 2010 11:51 pm
by Balveda
I'm still new at this, but struggling on slowly. I have a table in my db that details the characters in my WoW guild (sad, I know). The table has the following columns:

ID - primary key, auto increment, etc, etc
char1 - the character name
rank - characters guild rank
class - their class
max_lvl - yes/no to if they are max level
spec1 - their primary spec
spec2 - their secondary spec
role1 - the role defined by spec1, like tank, healer, etc
r1eg - yes/no to is the role 1 gear end-game level
role2 - the role defined by spec2
r2eg - yes/no to is the role 2 gear end game level

What I want to be able to do is search for (for example) all characters that are max level, have a tank spec, and that spec is end game geared.

I can do the form to post to a script, but have no clue how to go about this sort of search query. Could anybody point me in the right direction please?

Regards,

Balveda

Re: How to search multiple fields?

Posted: Mon Jul 26, 2010 1:24 am
by Christopher
SELECT * FROM characters WHERE max_lvl='yes' AND role1='tank' AND r1eg='yes'

Re: How to search multiple fields?

Posted: Mon Jul 26, 2010 5:26 am
by Balveda
Christopher wrote:SELECT * FROM characters WHERE max_lvl='yes' AND role1='tank' AND r1eg='yes'
Thanks dude, but how would I include the role2 and r2eg? As these could also hold the data that is being searched for.

Re: How to search multiple fields?

Posted: Mon Jul 26, 2010 10:30 am
by Christopher
For example, if you wanted records where either role was tank then.

SELECT * FROM characters WHERE max_lvl='yes' AND ((role1='tank' AND r1eg='yes') OR (role2='tank' AND r2eg='yes'))

This is logic, so you should play with combination to what they give you.

Re: How to search multiple fields?

Posted: Mon Jul 26, 2010 11:13 am
by Balveda
Thank you very much. I'm still struggling to get my head round mysql/php. I'll work on the script tonight and see how I get on :D