Properly format that code.
Feb 27, 2018
6
Level 1
Multiple select clauses not working properly in DB query
Hi, I'm running a query across 2 tables with unexpected results. When I use the following lines of code, the result ignores the clause "where users.userType = Student"
$searchword = Input::get ('q');
$student = \DB::table('userprofiles')->join('users', 'users.userName', '=', 'userprofiles.userName')->select('userprofiles.id','userprofiles.userName', 'userprofiles.fName', 'userprofiles.lName')->where('users.userType', '=', "Student")->where('userprofiles.userName', 'LIKE', '%' . $searchword . '%')->orwhere('userprofiles.fName', 'LIKE', '%' . $searchword . '%')->orwhere('userprofiles.lName', 'LIKE', '%' . $searchword . '%')->get();
I tried another method I found online:
$student = \DB::table('userprofiles')->join('users', 'users.userName', '=', 'userprofiles.userName')->select('userprofiles.id','userprofiles.userName', 'userprofiles.fName', 'userprofiles.lName')->where('users.userType', '=', "Student")->where(function($word){$word->where('userprofiles.userName', 'LIKE', '%' . $searchword . '%')->orwhere('userprofiles.fName', 'LIKE', '%' . $searchword . '%')->orwhere('userprofiles.lName', 'LIKE', '%' . $searchword . '%')})->get();
Then I get: FatalThrowableError Parse error: syntax error, unexpected '}'
What am I doing wrong?
Thanks.
Please or to participate in this conversation.