I have just started PHP programming and have the following scenario;
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";