0

query in plain php is

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

i have written query in yii2 is

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

but i m not getting the required result for the query in yii2

3 Answers 3

2

Try this way:

Followusers::find()->where(['follower' => $userid])    
   ->andWhere(['followed' => $conid])
   ->orwhere(['AND',
        ['followed' => $userid], 
        ['follower' => $conid]
    ])
   -> all();
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, perhaps it's more correct answer since I haven't coded in Yii for a while :)
0

If followusers table model is FollowUsers (in the current namespace, otherwise you have to prefix with namespace), you can

$data = FollowUsers::find()
->where(['AND', 'follower='.$followed1, 'followed='.$follower1])
->orWhere(['AND', 'follower='.$follower1, 'followed='.$followed1])
->all();

Otherwise, you can usign parameters:

$data = FollowUsers::find()
->where('(follower=:followed1 AND followed=:follower1) OR (follower=:follower1 AND followed=:followed1)', [':followed1' => $followed1, ':follower1' => $follower1])
->all();

Comments

0

It seems like you have some syntax errors in your code, try formatting it as follows:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.