php codeigniter MySQL search query

Posted by kalafun on Stack Overflow See other posts from Stack Overflow or by kalafun
Published on 2013-07-03T11:02:43Z Indexed on 2013/07/03 11:05 UTC
Read the original article Hit count: 183

Filed under:
|
|

I want to create a search query on MySQL database that will consist of 5 different strings typed in from user. I want to query 5 different table columns with these strings.

When I for example have input fields like:

first name, last name, address, post number, city.

How should I query the database that I dont always get all the rows.

My query is something like this:

SELECT user_id, username
from users
where
a like %?% AND
b like %?% AND
c like %?% AND
d like %?% AND
e like %?%;

When I exchange the AND for OR I always get all the results which makes sense, and when I use AND I get only the exact matches...

Is there any function or statement that would help me with this?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about query