这个查询要怎么写才对

发布于 2019-09-12 12:54:55

public function search11() {

    $rec = input();
    $model = model('Category');
    $row = $model->get($rec['pid']);
    $color = 'color';
    $pro = model('product');
    $pids = $model->field('id')->where('pid', $rec['pid'])->buildSql();
    $where[$color] = ['like', '%' . $rec['color'] . '%'];
    if ($rec['pid'] > 0) {
        $where['category_id'] = array('exp', ' IN ' . $pids);
    }
    $row2 = $pro->where($where)->select();
    $this->view->assign('row', $row);
    $this->view->assign('row2', $row2);

    return $this->view->fetch();
}


$where['category_id'] = array('exp', ' IN ' . $pids); 这句报错
我是要做子查询

category_id in (select id form b where pid = 2)要怎么写才对呢?

报错提示:

[0] Exception in Builder.php line 398
查询表达式错误:EXP

            $whereStr .= '(' . implode($array, ' ' . strtoupper($logic) . ' ') . ')';
        } else {
            $whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value, $field);
        }
    } elseif ('EXP' == $exp) {
        // 表达式查询
        if ($value instanceof Expression) {
            $whereStr .= '( ' . $key . ' ' . $value->getValue() . ' )';
        } else {
            throw new Exception('where express error:' . $exp);
        }
    } elseif (in_array($exp, ['NOT NULL', 'NULL'])) {
        // NULL 查询
        $whereStr .= $key . ' IS ' . $exp;
    } elseif (in_array($exp, ['NOT IN', 'IN'])) {
        // IN 查询
        if ($value instanceof \Closure) {
            $whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value);
        } else {
        

QQ图片20190912125734.png

查看更多

关注者
0
被浏览
99
1 个回答
胡小厨
胡小厨 4天前
这家伙很懒,什么也没写!

$map['id'] = array('in','1,5,8');

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览