I want all the hostel within the given price range from my hostel's table. price is stored into four different rows like price one share, price two shares, price three shares, price more share,
public function actionNearbyHostel($min,$max,$types,$lat,$long){
$latitude = $lat;
$longitude = $long;
$type = $types;
$max_price = (int)$max;
$min_price = (int)$min;
$hostels = Hostels::find ()->select("*,(6371 *
acos(cos(radians({$latitude}))*
cos(radians(`lat`)) * cos(radians(`log`) - radians({$longitude})) +
sin(radians({$latitude})) * sin(radians(`lat`)))) AS distance")
->having("distance<:distance")
->addParams([
':distance' => 5
])->where([
'status' => Hostels::ACTIVE,
'type' => $type
])->andWhere(['between','price_one_share',$min_price,$max_price])
->all();
return $this->render('filterhostel',[
'hostels' => $hostels,
]);
}
This is my action where I already have written
andWhere(['between','price_one_share',$min_price,$max_price])
like this, I want to include the remaining three rows and get my result.
this is my table row image http://www.clipular.com/posts/4991398571671552?k=Lud1W4LGJe5hSxOsl2ao7VOGguI
After some homework, I found the answer
public function actionNearbyHostel($min,$max,$types,$lat,$long){
$latitude = $lat;
$longitude = $long;
$type = $types;
$max_price = (int)$max;
$min_price = (int)$min;
$hostels = Hostels::find ()->select("*,(6371 * acos(cos(radians({$latitude}))*
cos(radians(`lat`)) * cos(radians(`log`) - radians({$longitude})) +
sin(radians({$latitude})) * sin(radians(`lat`)))) AS distance")
->having("distance<:distance")
->addParams([
':distance' => 5
])->where([
'status' => Hostels::ACTIVE,
'type' => $type
])->andWhere(['or',
['between','price_one_share',$min_price,$max_price],
['between','price_two_share',$min_price,$max_price],
['between','price_three_share',$min_price,$max_price],
['between','price_more_share',$min_price,$max_price]
])
->all();
return $this->render('filterhostel',[
'hostels' => $hostels,
]);
}