doushichi3678 2013-03-19 23:58
浏览 24

MySQL返回结果类似于字符串输入但没有句点

I have something in the database under the region column named "St. Catharines"

I would like to return the records containing "St. Catharines" from a string without the period. So, the string would be "St Catharines". Can this be done? How?

Right now I have:

$region = "St Catharines"; 
$query = " AND region like '" . $region . "%'";

Unfortunately, it does not work.

The period would always be absent from the $region string and could be anywhere within the database record (i.e. not just after "St").

  • 写回答

2条回答 默认 最新

  • douxun3496 2013-03-20 00:07
    关注

    You really shouldn't do that, it's not good, that should be fixed before hand.

    You can split the string by spaces (using explode), and search for example the two parts:
    Like a: $arr = explode(" ",$string);

    $query = " AND (region LIKE '".$arr[0]."%' OR '%".$arr[1]."%')";

    This would find as a result everything with "St" in the beginning and everything that contained "Catharines" in the result.

    That is the best solution to that problem, is partial matching, while it might show more results then the ones you want, another solution is something like mentioned here: stackoverflow question about removing commas and etc

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作