码迷,mamicode.com
首页 > 数据库 > 详细

think PHP提取字符串中的数字,并到数据库中使用in查询所关联表的字段值

时间:2019-05-06 17:29:12      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:sel   name   res   foreach   where   get   number   select   result   

    /*
     * 提取数字并去数据库取得相应的分类名
     * $strs 需要处理的字符串
     * $table 数据表名
     * $condition   条件字段
     * $field 获取的字段
     */
    public function extractNumberGetName($strs,$table,$condition,$field){
        if(empty($strs)){
            return ‘‘;
        }
        $patterns = "/\d+/"; 
        preg_match_all($patterns,$strs,$arr);
        if(empty($arr[0])){
            return ‘‘;
        }
        $map[$condition] = array (in,$arr[0]);
        $model = D($table);
        $result = $model->field($field)->where($map)->select();

        $str = ‘‘;
        $i = 0;
        foreach ($result as $key => $item) {
            if($i == 0 ){
                $str .= $item[$field];
            }else{
                $str .= ,.$item[$field];
            }
            $i++;
        }
        return $str;
    }

 

think PHP提取字符串中的数字,并到数据库中使用in查询所关联表的字段值

标签:sel   name   res   foreach   where   get   number   select   result   

原文地址:https://www.cnblogs.com/hardykay/p/10820808.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!