Better mysql select Query to filter data (PHP)?

Updated query for new question requirements.

Updated query for new question requirements Works for KIS KIS,(anything) at start (anything),KIS,(anything) at middle (anything),KIS at last Query SELECT * FROM users WHERE location = 'KIS' OR LIKE 'KIS,%' OR LIKE '%,KIS,%' OR LIKE '%,KIS.

Sorry that doesn't work for me becuase I need correct location not similar to KIS :-( – kevin Nov 24 at 8:43 Updated answer for exact match – Utku Yıldırım Nov 24 at 8:50.

If you need to find a part of input string you could use SELECT * FROM users WHERE location LIKE '%KIS%' If you need to get correct input you can use SELECT * FROM users WHERE FIND_IN_SET(LOWER('KIS'), LOWER(location)) > 0.

Kevin: I see now your comment; well, use my second example and your job should be done :) – Marco Nov 24 at 8:48.

Select username from users where location like '%KIS%.

Strval($_GET'search') : null; if($search) { $query = "SELECT * FROM users WHERE location LIKE '%". Mysql_real_escape_string($search)."%'"; $result = mysql_query($query); // if result fetch rows }.

Use regular expressions. SELECT * FROM users WHERE location RLIKE '(^|^_alnum)KIS($|^_alnum)' Or if your data is always separated by one comma, then use this: SELECT * FROM users WHERE location RLIKE '(^|,)KIS($|,)' But know that your database is not in 1st normal form, and storing complex data, and looking it up is going to greatly affect performance. If it's possible use a separate table to store the location for each user.

Thanks Zsolt that seems to be the real help and yes I will learn follow all the best practices coz I am learning a lot here on stack overflow – kevin Nov 24 at 8:54.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions