dr5648 2014-04-10 14:35
浏览 14
已采纳

从客户检索电话号码

The customers can have 3 different phone numbers, and I want to retrive these from the database, based on the numbers in my array phone.

function statsUserRing($phone, $link)
{
    $i = 0;
    $p1 = preg_replace( '/[^0-9]/', '', $phone[0]);
    $p2 = preg_replace( '/[^0-9]/', '', $phone[1]);
    $p3 = preg_replace( '/[^0-9]/', '', $phone[2]);

    while($get_stats = $link->get_object("SELECT REPLACE(telnr,'-', '') as telnr FROM ringupp WHERE telnr LIKE '%$p1%' OR telnr LIKE '%$p2%' OR telnr LIKE '%$p3%'"))
    {
        $i++;
    }

    return $i;

}

Im trying with a customer that have 2 phone numbers registred. So my array contains 2 values, which is these numbers.

Those 2 numbers appears 16 times in my ringupp table, but when I run my code above, it counts it to 204154. Why?

  • 写回答

3条回答 默认 最新

  • douying3251 2014-04-10 15:16
    关注

    You can achieve this using only SQL:

    SELECT  REPLACE(telnr,'-', '') as telnr 
    FROM    ringupp
    WHERE   (telnr LIKE '%$p1%' AND '$p1' <> '')
    OR      (telnr LIKE '%$p2%' AND '$p2' <> '') 
    OR      (telnr LIKE '%$p3%' AND '$p3' <> '');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂