dongyakui8675 2014-04-10 09:42
浏览 40
已采纳

从连字符返回没有连字符的字符串

Im trying to retrive a customer phone numbers from the an table. The problem is that I want to remove all the occurring hyphens in the phone numbers while I'm doing an SELECT. Should I use REPLACE?

function statsUserRing($phone) //Phone is an array containing phone numbers
{
    foreach($phone as $p)
    {
        $p_mod = str_replace('-', '', $p); //Remove the hyphens from the phone numbers in the array

        $get_stats = $link->get_object("SELECT REPLACE($p,'-', '') FROM ringupp WHERE telnr='$p_mod'");

    }
}

I want to get the records in the ringupp table, based on the phone numbers in the array, but the phone numbers in the table ringupp contains phone numbers with hyphen, but I want to remove the hyphens while im doing the select.

The column that I want to get is called telnr in the table.

Hope you understand me. :)

  • 写回答

1条回答 默认 最新

  • duanhemou9834 2014-04-10 09:52
    关注

    I'm assuming that you you want to find the record where the numbers match while ignoring the underscores. To do so you'll need to use something like :

    SELECT <field(s)> FROM ringupp WHERE REPLACE(telnr,'-', '') ='$p_mod'
    

    Mind you that this will be terribly slow as the system will need to scan the entire table to match the 'cleaned-up telnr' with the required one and thus cannot (efficiently) make use of its indexes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟