我有一個動態形成的多個div。在每個div裏面我都有一個複選框和一個下拉列表。複選框列表包含酒店名稱和類別以及包含酒店評級的單個下拉菜單。用戶可以選擇複選框或從下拉列表中選擇一個選項。默認情況下是複選框。如果用戶沒有選擇複選框,則應考慮特定城市的下拉列表的值。顯示來自帖子的數組php
這是我在控制器中試過的代碼,但我沒有得到想要的結果。有人可以幫我解決這個問題嗎?
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);
}
感謝,
什麼是確切的問題? –
你想要的結果是什麼? –
只要提到如果您使用複選框的不同名稱和下拉框表示您可以通過選中複選框的空值幷包含下拉框的值來獲得結果 – Kalai