我现在正试图在用户选择某些条件后制作相应的结果列表。
我在控制器中写的内容:
$temp="SELECT
v_realestates.house_Id,
v_realestates.unit_Price,
w_builds.tran_Area,
x_lands.Ltran_TotArea,
y_parkinglots.parking_Price
FROM
w_builds
LEFT OUTER JOIN
x_lands ON x_lands.house_Id = w_builds.house_Id
LEFT OUTER JOIN
v_realestates ON v_realestates.house_Id = w_builds.house_Id
LEFT OUTER JOIN
y_parkinglots ON y_parkinglots.house_Id = w_builds.house_Id
WHERE
x_lands.house_Id = w_builds.house_Id = v_realestates.house_Id = y_parkinglots.house_Id ";
if (@$_GET['city']!="") {
$temp=$temp." and v_realestates.the_Location like '%".$_GET['city']."%'";
}
if (@$_GET['district']!="") {
$temp=$temp." and v_realestates.the_Location like'%".$_GET['district']."%'";
}
if (@$_GET['unit_Price']!="") {
if(@$_GET['unit_Price']=="un1"){
$temp=$temp." and v_realestates.unit_Price between 0 and 200000";
}
else if(@$_GET['unit_Price']=="un2"){
$temp=$temp." and v_realestates.unit_Price between 200001 and 400000";
}
else if(@$_GET['unit_Price']=="un3"){
$temp=$temp." and v_realestates.unit_Price between 400001 and 600000";
}
}
if (@$_GET['tot_Price']!="") {
if(@$_GET['tot_Price']=="to1"){
$temp=$temp." and v_realestates.tot_Price < 9000000";
}
else if(@$_GET['tot_Price']=="to2"){
$temp=$temp." and v_realestates.tot_Price between 9000000 and 15000000";
}
else if(@$_GET['tot_Price']=="to3"){
$temp=$temp." and v_realestates.tot_Price between 15000001 and 25000000";
}
}
$query = DB::select($temp);
$theNum = DB::select('SELECT COUNT(house_Id) AS houseNum FROM v_realestates');
$theunPrice = DB::SELECT('SELECT ROUND(AVG(unit_Price),-4) AS avgunPrice FROM v_realestates');
$thetotPrice = DB::SELECT('SELECT ROUND(AVG(tot_Price),-4) AS avgtotPrice FROM v_realestates');
}
$page = Paginator::resolveCurrentPage("page");
$perPage = 10;
$offset = ($page * $perPage) - $perPage;
$X_land= new LengthAwarePaginator(array_slice($query, $offset, $perPage, true), count($query), $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
return \View::make('holyfive.generalsearch', compact('X_land','theNum','theunPrice','thetotPrice'));
刀片中有什么:
<div class="searchresult2">
<ul>
@foreach($theNum as $Num)
<li id="areatitle">[ Total row<span class="numberofresult">{{ $Num->houseNum }}</span> ]</li>
@endforeach
@foreach($theunPrice as $unPrice)
<li>The unit price <br><span class="resultprice">{{ $unPrice->avgunPrice/10000 }}</span></li>
@endforeach
@foreach($thetotPrice as $totPrice)
<li>The total price <br><span class="resultprice">{{ $totPrice->avgtotPrice/10000 }}</span></li>
@endforeach
</ul>
</div>
我知道上面的一个可以获得house_Id
的总数并在数据库中计算unit_Price
。我试图根据用户从下拉列表中选择的内容将此更改为交互式,我应该如何计算theNum
theunPrice
thetotPrice
。
感谢您给我任何建议。