Android : PHP search query, make it like android contacts search

on Wednesday, September 10, 2014


I have tried to implement search in my gadget using LIKE query.


Now i have this new requirement where i have to make this search like the Android Search..


Query:



$stmt = $conn->prepare("SELECT ROOM, GUEST_NAME, GUEST_FIRST_NAME, CONFIRMATION_NO, DEPARTURE, PWD FROM RESERVATION_GENERAL_2 WHERE LOWER(GUEST_FIRST_NAME) LIKE ? OR LOWER(GUEST_NAME) LIKE ?");
$stmt->execute(array('%'.strtolower($searchFilter).'%','%'.strtolower($searchFilter).'%' ));


Let Suppose i have a String Syed Haider Hassan in database and if i search san in the database table using the given query, it will find me this above string. Hence if i put anything that matches inside or anywhere in string it will get me this string,


But what i want is that when i search in database Hai or Has or Sy it should get me this string, but if i search san or even assan, the query should not show me the this string. Means if i search it must do search with startwith, not from middle. i think it might be possible if i remove % from start, but problem is then query will only see startwith on Syed, i want it apply startwith on every word as words are seperated by space. Search Syed Haider Hassan differetly..


I know what i tried to explain above is very confusing, mostly because i am not good in english. But in simple words if you have Android Mobile, i have Galaxy S4, search any name in your contacts book. if you search from middle of word it will not search but if you search from start of word it will search, but thats just not it. if your contact name is combination of two words separated by space then it will also check for first Alphabet of second word.


I hope i am clear, but i dont know how to implement that query. Please if anyone can update my query to this new search criteria, i will be very gladful.


0 comments:

Post a Comment