0

I have an multiple divs which are formed dynamically. Inside each div i have a list of checkboxes and a single dropdown. The list of checkboxes contain the hotel name and category and a single dropdown containing the hotel rating. The user can select the checkboxes or select an option from the dropdown. By default is the checkbox. If the user does not select the checkbox then the value of the dropdown should be taken into consideration for the particular city.

This is the code that i have tried in the controller but i am not getting the desired result. Can someone help me with this pls?

       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);
            }

Thanks,

2
  • Just mention how to get the results if you use the different name for the checkbox and dropdown box means you can do it by checking the checkbox empty value and include the dropdown box value Commented Oct 12, 2012 at 5:53
  • It is like if the user does not select the checkbox then the dropdown value for the particular country should be selected.$_POST['hotel'] is the checkbox value and $_POST['category'] is the dropdown value. Commented Oct 12, 2012 at 6:11

3 Answers 3

2

in the checkbox input tag keep the name as "city[]" not just "city" and then in your controller retrieve as $this->input->post['city[]'], it will return the array of the values checked. otherwise you you use just "city" then only last checked value will appear here. so i would say try using "city[]", hope it helps

Sign up to request clarification or add additional context in comments.

Comments

0

Based on your Question 'displaying the array from the post php' I'll just say

echo '<pre>';
print_r($_POST);
echo '</pre>';

It'll help you inspect your posted data

1 Comment

I did that i am getting the data. My problem is to display it in a format which meets my condition mentioned above
0

I think you are missing the condition for empty variable. Try something like this

if (isset($_POST['city']) && !empty($_POST['city']))

Just do the same on the others :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.