Get states by Country
---------------------

I created three option box to selecting area, state and Country. The problem is country working well however when I want to get city and area that gives me error undefined variable in other scripts which I used that is worked.

Undefined variable: country\_id 

Controller
----------

```
public function get_city()
{   
    $this->load->model('cities_model');
    header('Content-Type: application/json');

    $country_id = $country_id?$country_id:$this->input->post('country_id');
    if($country_id) 
    echo json_encode($this->cities_model->get_city());
}

```

Model
-----

```
public function get_city($country_id = 0){
    return 
    $this->db->select('name as text, city_id as value')
            ->where('country_id', $country_id)
            ->get('cities')
            ->result();
 }

```

View
----

```
<li>
                            <label class="form-label required">Country</label>
                            <div class="form-item">
                                <select class="selectpicker" name="country_id" data-url="/admin/events/get_countries" data-select="city-1" data-select-group="1" required></select>
                            </div>
                        </li>   
                        <li class="hide" data-select-group="1" data-select-sub="city-1">
                            <label class="form-label required">City</label>
                            <div class="form-item">
                                <select class="selectpicker" name="city_id" data-url="/admin/events/get_city" data-select="area-1" required></select>
                            </div>
                        </li>                                    
                        <li class="hide" data-select-group="1" data-select-sub="area-1">
                            <label class="form-label required">Area</label>
                            <div class="form-item area_id">
                                <select class="selectpicker" name="area_id" data-url="/admin/events/get_area" required></select>
                            </div>
                        </li>

```