我有一个动态形成的多个 div。在每个 div 中,我都有一个复选框列表和一个下拉列表。复选框列表包含酒店名称和类别以及包含酒店评级的单个下拉列表。用户可以选择复选框或从下拉列表中选择一个选项。默认情况下是复选框。如果用户未选中该复选框,则应针对特定城市考虑下拉列表的值。
这是我在控制器中尝试过的代码,但我没有得到想要的结果。有人可以帮我吗?
if (isset($_POST['city'])) {
$city = $_POST['city'];
if (is_array($city)) {
foreach ($this->input->post('city') as $city) {
$cityid[] = $city;
// $category.= $this->input->post('category_' . $city) . ",";
// $categorycity.= $city . ",";
// $prefsightseeing.= $this->input->post('prefsight_' . $city) . ",";
// $prefsightseeingcity.= $city . ",";
//$hotel = $_POST['hotel'];
if (isset($_POST['hotel'])) {
$hotel = $_POST['hotel'];
// if (is_array($hotel) && in_array($city, $hotel)) {
foreach ($this->input->post('hotel') as $city_id) {
$arr = explode('_', $city_id);
if (in_array($arr[1], $cityid)) {
$hotelcityid.= $arr[1] . ',';
$hotelid.= $arr[2] . ',';
}
// }
}
}
else{ if (isset($_POST['category'])) {
$category = $_POST['category'];
foreach ($this->input->post('category') as $category) {
$arr = explode('_', $category);
// echo $arr[1];
// print_r($cityid);
if (in_array($arr[1], $cityid)) {
$hotelcategory.= $arr[0] . ',';
$categorycity.= $city . ',';
}
}
}
}
// $hotelid.= $arr[2] . ',';
}
$categorycity = rtrim($categorycity, ',');
$category = rtrim($hotelcategory, ',');
$category= implode(',', array_keys(array_flip(explode(',', $category))));
$categorycity= implode(',', array_keys(array_flip(explode(',', $categorycity))));
// $prefsightseeing = rtrim($prefsightseeing, ',');
// $prefsightseeingcity = rtrim($prefsightseeingcity, ',');
}
}
if ($category != "") {
$arrData['HotelInfoByCategory'] = $this->previewpackage_model->get_hotel_info_by_category($category, $categorycity);
}
谢谢,