My data bse field are
table name: t_category
category_id
category_name
table name: t_category
sub_category_id
sub_category_name
table name: t_news
news_id
news_name
sub_category_id
news_title
discription
In my news form i need category and sub category dropdowns. But in my news table i have only one field that is 'sub_category_id'. So how can i take two fields in form with one one field(in database).
Iam adding one fake field(custom field) for category drop down that is:
I wrote in my controller
$crud->fields('category_id','sub_category_id','news_title','discription');
$crud->callback_add_field('category_id',array($this,'add_field_callback_1'));
function add_field_callback_1()
{
$this->load->library('grocery_CRUD');
$crud = new grocery_CRUD();
$empty_select = '<select id="field-category_id" name="category_id" class="chosen-select chzn-done" data-placeholder="Select Category" style="width: 300px;display: none;"><option value=""></option>';
$empty_select_closed = '</select>';
$empty_select_closed1='<div style="width: 300px;" class="chzn-container chzn-container-single" id="field_category_id_chzn">
<a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1">
<span>Select Category</span><div><b></b></div></a>
<div class="chzn-drop" style="left: -9000px; width: 510px; top: 30px;"><div class="chzn-search">
<input style="width: 490px;" autocomplete="off" type="text"></div>
<ul class="chzn-results">';
$this->db->select('*')
->from('t_category')
->where('module_id', 24);
$db = $this->db->get();
$i=1;
foreach($db->result() as $row):
$empty_select .= '<option value="'.$row->category_id.'" >'.$row->category_name.'</option>';
$empty_select_closed1.='<li id="field_category_id_chzn_o_'.$i.'" class="active-result" style="">'.$row->category_name.'</li>';
$i++;
endforeach;
$empty_select_closed1.='</ul></div></div>';
$html = '<link type="text/css" rel="stylesheet" href="'.base_url().'/assets/grocery_crud/css/jquery_plugins/chosen/chosen.css" />';
$html .= '<script src="'.base_url().'/assets/grocery_crud/js/jquery_plugins/jquery.chosen.min.js"></script>';
$html .= '<script src="'.base_url().'/assets/grocery_crud/js/jquery_plugins/config/jquery.chosen.config.js"></script>';
return $empty_select.$empty_select_closed.$empty_select_closed1;
}
Drop down list is coming. But is not working..? Please give any solution?