I am just starting to learn php and mysql, and am creating a project using php and mysql. I am stuck while searching and filtering the data from the database. The search is basically a combined search and filter the data according to the user inputs.
Here is my code:
public function filterSearch(Request $request){
$new = $request->get('new');
$used = $request->get('used');
$registered = $request->get('registered');
$make = $request->get('make');
$model = $request->get('model');
$price = $request->get('price');
$city = $request->get('city');
$registration = $request->get('firstRegistration');
$query = DB::select("SELECT * FROM ads WHERE vehicleCond LIKE '".$new."' OR vehicleCond LIKE '".$used."' OR vehicleCond LIKE '".$registered."' ");
$decode = json_decode(json_encode($query),true);
$finalArr = array();
for($i=0; $i<count($decode); $i++){
if($make || $model || $registration){
if(($decode[$i]['make'] == $make) || ($decode[$i]['model'] == $model) || ($decode[$i]['registration'] == $registration)){
array_push($finalArr,$decode[$i]);
}
}else{
array_push($finalArr,$decode[$i]);
}
}
return response()->json(['success'=>$finalArr], 200);
}
The result is not correct...for single selection, it is working fine. When I used the combination, then the result is not correct.
