PHP T9手机键盘[关闭]

I have just started PHP programming and have the following scenario;

  1. My contact list is saved in mysql database (Fname, Lname, phone) = done
  2. Take user input as imagining it taking from a mobile keypad .i.e. 'abc' corresponds to 1, 'def corresponds to 2 etc.
  3. Let's say user enters "738"...this would correspond to 'PET' and so will 'REU'.
  4. What the php code is suppose to do is get the user input in the form of digits and search through the mysql database going through the last name to see if it corresponds to any of the name and finally list those contact(s). However, since 'SET' is also a valid combination of 738 BUT if it does not exist in the database, it will not get displayed.

Question: how can i take the input in digits and generate all possible combination to match against the database? I guess i will have to use arrays to store the mobile keypad mapping and somehow do the permutations stuff. Any help will be appreciated.

I would love to hear more about the use case where this is still worth programming in 2014.

If you really wanted to do this, you COULD enumerate all the possibilities and search that way, such as:

222 = AAA, AAB, AAC, ABA, ABB, ABC, ACA, ACB, ACC, BAA, BAB, BAC,  BBA, BBB, BBC, BCA, BCB, BCC, CAA, CAB, CAC, CBA, CBB, CBC, CCA, CCB, CCC

Which is 3 cubed (27) possibilities.

However if you have 7 numbers you have 3^7th, or 2187 permutations, which is going to be an ungodly OR LIKE 'AAAAAAA%' chain.

However this method is backwards. What you should do is add a mobile-keypad-name for any name you want to search with this method, and pre-populate it with the representative digits- there will only be one possibility per name.

The SQL lookup is then a straight shot:

WHERE mobile-keypad-name = "2222222";