mysql根据数组中的值查找

文章描述:

SQL查询一个字段多个值的使用方式

比如需要查找多个电话号码的方式

arr

数组

$arr = array('183****2362','173****2362');

分割

$condition = implode(',', $arr);

 

拼装SQL

$sql = "SELECT * FROM ".$sys->table('code');
    
if(count($arr)>0){
        $sql .= " WHERE mobile in(".$condition.") ";
}
    
$sql .=" LIMIT 0,100 ";

 

打印SQL结果:

SELECT * FROM `crh_sys`.`cr_code` WHERE mobile in(183****2362,173****2362) LIMIT 0,100

from adm-chuanronghui-com tool

 

left join

sms_user数据表相当于$arr里面这种存在数据库里面的数据

$SmsUser_model = M("sms_user as a");

$items = $SmsUser_model
            ->field('a.name,b.*')
            ->join('JOIN '.C("DB_PREFIX").'phone_code as b ON a.mobile = b.phone')
            ->select();

from Semsystem MobileSms

发布时间:2022/10/28

发表评论