Question : The best way to search a Database

My Goal is to search the First name, Last Name, & Cell phone columns and at the same time filter the results so that if the record isnt set to be viewable it isnt returned. the code i included works fine, but im new to programing and ive seen people talk about 'bad queries' crippling databases, so I am wanting to know if this is the appropriate way to search multiple columns and filter the results.

1:
"SELECT * FROM members where `members`.`view` != '0' and members.last LIKE '$varsearch' or `members`.`view` != '0' and members.first LIKE '$varsearch' or `members`.`view` != '0' and members.cell LIKE '$varsearch'"

Answer : The best way to search a Database

You should enclose your logical operations, else the ORs are useless in there:
SELECT * FROM members
where (`members`.`view` != '0' and members.last LIKE '$varsearch') or (`members`.`view` != '0' and members.first LIKE '$varsearch') or (`members`.`view` != '0' and members.cell LIKE '$varsearch')

Alternatively:
SELECT * FROM members
where `members`.`view` != '0' and (members.last LIKE '$varsearch' or members.first LIKE '$varsearch' or members.cell LIKE '$varsearch')
Random Solutions  
 
programming4us programming4us