我在哪裏搜索產品的幾個科目的形式,我也有一個HTML選擇了PHP的切換工作,使排序結果的順序的能力。這個現任職於搜索表單,我想做出排序的HTML選擇不點擊搜索按鈕,工作和每一個它的改變時運行正確的選擇選項,並立即改變產品的爲了匹配選擇選項。分離一種由過濾器/選擇
下面是HTML:
{!! Form::open(['route' => 's.index', 'method' => 'GET']) !!}
<div class="form-group">
{!! Form::label('productsname', 'Search By Name:') !!}
{!! Form::text('productsname', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
{!! Form::label('categories_id', 'Search By Category:') !!}
<select class="form-control" name="categories_id" >
<option value=""></option>
@foreach($types as $type)
<option value="{{$type->id}}">{{$type->name}}</option>
@endforeach
</select>
</div>
</div>
<div class = col-md-6>
<div class="form-group">
</div>
</div>
<div class="form-group">
<select class="form-control" name="SortbyList" >
<option value="1">Highest Avg</option>
<option value="2">Lowest Avg</option>
<option value="3">Another Sort option</option>
<option value="2">another sort option</option>
</select>
{!! Form::submit('Find Products', array('class' => ' btn-lg btn-block')) !!}
{!! Form::close() !!}
</div>
這裏是PHP:
public function index(Request $request)
{
//
$productsQuery = Product::where('approved', '=', 1)->leftJoin('reviews', 'reviews.products_id', '=', 'products.id')->select('products.*', DB::raw('AVG(ratings) as ratings_average'))->groupBy('products.id');
switch ($request->SortbyList) {
case 1:
$productsQuery = $productsQuery->orderBy('ratings_average', 'DESC');
break;
case 2:
$productsQuery = $productsQuery->orderBy('ratings_average', 'ASC');
break;
case 3:
$productsQuery = $productsQuery->orderBy('ratings_average', 'ASC');
break;
case 4:
$productsQuery = $productsQuery->orderBy('ratings_average', 'ASC');
break;
default:
$productsQuery = $productsQuery->orderBy('ratings_average', 'DESC');
}
$name=$request->input('productname');
$location=$request->input('categories_id');
if(!empty($name)){
$sightsQuery->where('productname', 'LIKE', '%'.$name.'%')->get();
}
if(!empty($location)){
$sightsQuery->where('categories_id', $request->input('categories_id'))->get();
}
$products= $productsQuery->paginate(8);
return view('p.search')->withproducts($products);
}
是什麼問題?你能指望什麼? –
我希望選擇作爲一個獨立的,而不是在按鈕按下時搜索它的形式。我希望能夠點擊選擇選項,並且頁面立即響應搜索結果。如果你需要一個例子,想想大多數購物車網站他們有一個由A - Z排序等我想能夠有一個單獨的排序。 – detinu20