在普通的PHP查询是

$p = "SELECT * FROM followusers WHERE (follower='$followed1 and
    followed='$follower1') or (follower='$follower1' and
    followed='$followed1')"


我在yii2中写过查询是

 $y = Followusers::find()->where(['follower' => $userid ] and
 ['followed' => $conid])->orwhere(['followed' => $userid ] and
 ['follower' => $conid])-> all();


但是我没有在yii2中获得查询所需的结果

最佳答案

尝试这种方式:

Followusers::find()->where(['follower' => $userid])
   ->andWhere(['followed' => $conid])
   ->orwhere(['AND',
        ['followed' => $userid],
        ['follower' => $conid]
    ])
   -> all();

关于php - 在yii2中使用多个where条件编写查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38281591/

10-11 20:11