SELECT COUNT(*) FROM tab WHERE tel LIKE '134%' or LIKE '135%' or LIKE '136%' or LIKE '137%' or LIKE '138%' or LIKE '139%'

解决方案 »

  1.   

    $i = 0;
    $results = mysql_query("select * from $tab");
    foreach($row = mysql_fetch_array( $results ))
    {
      $sja=substr($row[tel],0,3);
      if ($sja=="134" || $sja=="135" || $sja=="136" || $sja=="137" || $sja=="138"        ||     $sja=="139" || $sja=="159")
    $i++;  
    }
    echo "移动手机号有$i个";
      

  2.   

    SELECT COUNT(*) FROM tab WHERE tel LIKE '134%' or tel LIKE '135%' or tel LIKE '136%' or tel LIKE '137%' or tel LIKE '138%' or tel LIKE '139%'
      

  3.   

    $cmccCount = 0;
    $cmcc = array("^134","^135","^136","^137","^138","^139","^159");$link = mysql_connect("","","") or die("conn error");
    mysql_select_db("test",$link) or die("select db error");
    $result = mysql_query("SELECT * FROM `tablename`");
    $totle = mysql_num_rows($result);
    while($rows=mysql_fetch_array($result)){
    $phoneNum = $rows[tel];
    for ($i=0;$i<=count($cmcc)-1;$i++){
    if(ereg($cmcc[$i],$phoneNum)){
    $cmccCount++;
    echo $phoneNum."<br>\n";
    }
    }
    }
    $unionCount = $totle-$cmccCount;
    echo "共有移动号码:$cmccCount 个<br>\n";
    echo "共有联通号码:$unionCount 个";
    @mysql_close($link);
      

  4.   

    直接用sql进行like查询就行了,为啥非要拿php判断
    建议你的数据表多建立一个字段,用来存储手机号码的前3位。以后再查的时候就不用like了。效率高了不少