Hello,
i am new to grocerycrud and this my first post here
i have implemented the Dependent dropdown (library) (/topic/1087-updated-24112012-dependent-dropdown-library/) to achive the dependent field of country, state, city tables
the simple purpose is to show related states when some country is selected and also related cities to be shown when some state is selected.
i have achieved this reading the instructions and discussion on forum, very thanks to @victor
however i am stuck at a point now, i only want to show the cities and states that have status equal to true and active in my database
i not able to find a way or method using which i can do so.
can someone please help me doing this, when i select a country, i should only get the list of all active (status=1) states in that country, and same way when i select a state i should get a list of all active (status=1) cities in that state.
i hope the question is not confusing, please check the below code and attached database for reference
Any help or suggestions would be very helpful to me
public function index() {
try {
$this->load->library('ajax_grocery_CRUD');
$crud = new ajax_grocery_CRUD();
$crud->where('advertisements.status','1');
$crud->set_theme('datatables');
$crud->set_table('advertisements');
$crud->set_subject('Advertisements');
$crud->fields('module_id', 'category_id', 'country_id' , 'state_id' , 'city_id' , 'frame_location' ,
'start_date' , 'end_date' , 'image' , 'firstname' , 'lastname' ,
'address' , 'contact' , 'email' , 'price' ,'date_modified' , 'date_create');
$crud->field_type('module_id', 'dropdown', array('1' => 'fanchise', '2' => 'service',
'3' => 'coupon'))
->field_type('frame_location', 'dropdown' , array('1'=>'Home Page' ,
'2'=>'Internal Page'));
$crud->set_field_upload('image' , 'assets/uploads/advertisements');
$crud->columns('module_id', 'name', 'parent_id');
$crud->set_relation('category_id', 'categories', 'name');
$crud->set_relation_dependency('category_id','module_id','module_id');
$crud->set_relation('country_id','countries','name');
$crud->set_relation('state_id','states','name');
$crud->set_relation_dependency('state_id','country_id','country_id');
$crud->set_relation('city_id', 'cities', 'name');
$crud->set_relation_dependency('city_id','state_id','state_id');
$crud->display_as('module_id', 'module')
->display_as('category_id', 'category')
->display_as('city_id', 'city');
$crud->required_fields('module_id', 'category_id', 'country_id' , 'state_id' , 'city_id' , 'frame_location' ,
'start_date' , 'end_date' , 'image' , 'firstname' , 'lastname' ,
'address' , 'contact' , 'email' , 'price');
$crud->change_field_type('date_create','invisible');
$crud->change_field_type('date_modified','invisible');
$crud->callback_delete(array($this, 'delete_advertisements'));
$output = $crud->render();
$output->subject = "Advertisements";
$this->_advertisements_output($output);
} catch (Exception $e) {
show_error($e->getMessage() . ' --- ' . $e->getTraceAsString());
}
}
function insert_data_callback($post_array) {
$post_array['date_create'] = date('Y-m-d H:i:s');
$post_array['date_modified'] = date('Y-m-d H:i:s');
return $post_array;
}
public function delete_advertisements($primary_key) {
return $this->db->update('advertisements', array('status' => 0), array('id' => $primary_key));
}
function _advertisements_output($output = null) {
$this->load->view('view.php', $output);
}
[attachment=816:database.jpg][attachment=817:img.png]