dongwu5801 2014-02-09 00:34
浏览 35

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.

  • 写回答

1条回答 默认 最新

  • dongmuyan5638 2014-02-09 00:58
    关注

    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";
    
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法