cyandi_man Posted January 25, 2009 Share Posted January 25, 2009 Hi guys - i have a mini search page on my site in which i want people to be able to pull contact info by either typing in a Phone number or Company name in the search fields. Question is: 1. how do i have php compare the Phone number entered and phone number on database by just verifying that they have the same numbers in the same sequence? (ignoring any brackets or dashes) 2. how do i have the Company Name field search the database for any word that was entered in the input field excluding "the" Please advise ...thanks fellas! Quote Link to comment https://forums.phpfreaks.com/topic/142344-directory-search/ Share on other sites More sharing options...
MadTechie Posted January 25, 2009 Share Posted January 25, 2009 With the phone number you should filter it before its inserted and then format the output ie $Phone= preg_replace('/[^0-9]/i', '', $Phone); 555-1234 becomes 5551234 you can then do the same with the search to search for "any" you need to use LIKE and % as wildcards ie SELECT * FROM table WHERE company LIKE "%freaks%"; //contains freaks SELECT * FROM table WHERE company LIKE "freaks%"; //Starts with freaks SELECT * FROM table WHERE company LIKE "%freaks"; //Ends with freaks Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/142344-directory-search/#findComment-745843 Share on other sites More sharing options...
cyandi_man Posted January 25, 2009 Author Share Posted January 25, 2009 With the phone number you should filter it before its inserted and then format the output ie $Phone= preg_replace('/[^0-9]/i', '', $Phone); 555-1234 becomes 5551234 you can then do the same with the search Hope that helps your awsome dude! thanks! - question is though ...how do i INSERT the brackets and dashes when displaying the phone number? i suppose i would have a function that puts a "(" in front of the string and then counts 3 digits and puts a ")" and then counts 3 digits and then put a "-". but whats the proper format for the code? Quote Link to comment https://forums.phpfreaks.com/topic/142344-directory-search/#findComment-746023 Share on other sites More sharing options...
DeanWhitehouse Posted January 25, 2009 Share Posted January 25, 2009 yep Quote Link to comment https://forums.phpfreaks.com/topic/142344-directory-search/#findComment-746061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.