Search code examples
phpmysqlsearchstring-matching

Is it possible to match string with database entry and get result where a part of string get matched?


Actually I am saving my user's number i:e

+92 3123456789

in database without their country code i:e

3123456789

But the problem is that user can have saved the same number in his contact book but may be with country code i:e

+92 3123456789

or with local code i:e

03123456789

So, whenever i have to search for that number i have search for 03123456789 or may be +92 3123456789 from database record which is saved without country or local codes i:e 3123456789.

So, please help me get out of this problem. Thank you.


Solution

  • Thanks for all who assist me in this problem. But i have found the solution on my own by running simple query which mysql function CONCAT i:e

    select * from users where '03123456789' LIKE CONCAT('%', phone, '%')

    and for bulk contacts array search

    select * from users where '03123456789' LIKE CONCAT('%', phone, '%') OR '+923123456789' LIKE CONCAT('%', phone, '%')