Reputation: 11
I'm new to this field.I'm working on my very first system with CodeIgniter.Im using grocery crud for the crud functions.I have created two tables called "pavings" and "category".In the "paving table" there is a drop down list to select a category.When I add a category to the "category table" i want that added category name to display in the drop down list of paving table.
This is the coding of paving table.I just passed values of the drop down using an array,but it is not what I want.I wanted it to updated by the data of category table(with category column data)Please give me a answer to this.Thank you!
public function paving_management()
{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('tbl_pavings');
$crud->set_subject('Pavings');
$crud->fields('type','category','color','size','qnt_per_sqft','unit_price'); //field we want to add,edit,delete
$crud->columns ('paving_id','type','category','color','size','qnt_per_sqft','unit_price'); //fields we want to view
//$crud->unset_columns('paving_id'); // columns we dont want to view
$crud->display_as('type','Type')
->display_as('category','Category')
->display_as('qnt_per_sqft','Quantity per sqft')
->display_as('size','Size')
->display_as('unit_price','Unit Price')
->display_as('paving_id','Paving ID')
->display_as('color','Colour');
$crud->unique_fields('type'); // This field must be unique
$crud->required_fields('type','category','color','qnt_per_sqft','unit_price'); //this field are cmplsry
$crud->field_type('type','dropdown',
array('cobble smooth' => 'Cobble Smoothe','uni smooth' => 'Uni Smoothe','i smooth' => 'I Smoothe','panda smooth' => 'Panda Smooth','bat smooth' => 'Bat Smooth')); //drop down
$crud ->field_type('category','multiselect',
array( "heavy duty" => "Heavy Duty", "drive ways" => "Drive Ways")); //multiselect
$crud ->field_type('color','multiselect',
array( "red" => "Red", "brown" => "Brown", "green" => "Green"));
Upvotes: 0
Views: 1021
Reputation: 2617
Check this sample code for creating dropdown in codeigniter.
<?php
$js = 'id="unicode" class="form-control"';
$unicode = array(
'2' => 'No',
'1' => 'Yes'
);
echo form_dropdown('unicode', $unicode, set_value('unicode'), $js);
?>
Here Dropdown id is unicode,class is form-control.
Html will look like :
<select name="unicode" id="unicode" class="form-control">
<option value="2">No</option>
<option value="1">Yes</option>
</select>
You can get you values from db in an array and then store it in a variable like $unicode
.Hope this helps.Check this ref link
Upvotes: 1