我正在尝试使用where条件获取查询结果。我当前的查询是
$last_query = DB::table('user_matchs')->where('matched_user_id', '=', $UserId)->where('status','=','friend')->lists('user_id');
$mid_query = DB::table('user_matchs')->where('user_id', '=', $UserId)->lists('matched_user_id');
$query = DB::table('users')
->where('id', '!=', $UserId)
->whereNotIn('id',$mid_query)
->whereNotIn('id',$last_query);
$getchat_details = DB::table('preferences')->where('UserId', $UserId)->first();
if($getchat_details->ShowMan == 'true')
{
$query->where('gender', '=', 'male');
}
else {
$query->where('gender', '=', 'female');
}
$users = $query->get();
return Response::json($users );
}
在我的查询中,条件不起作用,使用if else conditon
添加答案 0 :(得分:0)
您可以事先确定要查询的性别。
if($getchat_details->ShowMan == 'true') {
$gender = 'male';
} else {
$gender = 'female';
}
$query = DB::table('users')
->where('id', '!=', $UserId)
->where('gender', $gender)
->whereNotIn('id',$mid_query)
->whereNotIn('id',$last_query);