Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/142344-directory-search/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/142344-directory-search/#findComment-745843
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/142344-directory-search/#findComment-746023
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.