logo

JTBC5.0多条件查询数据or的使用

2025-02-19 点击 56

例如查询一个字段ab的值为$a或$b时,输出结果

就需要添加这样的查询条件来实现

      $model -> where(function($where) use ($a,$b){
		$where -> ab = $a;
		$where -> ab -> or = $b;
      });

 或者不同字段

        $model -> where(function($where) use ($keyword){
            $where -> title -> like('%' . $keyword . '%');
            $where -> content -> or-> like('%' . $keyword . '%');
        });

例子代码

    $model = new TinyModel();
    $model -> where -> published = 1;
    $model -> where -> lang = $lang;
    $model -> where(function($where) use ($a,$b){
        $where -> ab = $a;
        $where -> ab -> or = $b;
    });
    $model -> orderBy('time', 'desc');
    $datas = $model -> getAll();



0%