suppose my control look like this: just part of the code:
<?php
public function orders()
{
if (!$this->ion_auth->logged_in())
{
//redirect them to the login page
redirect('auth/login', 'refresh');
}
elseif (!$this->ion_auth->is_admin()) //remove this elseif if you want to enable this for non-admins
{
//redirect them to the home page because they must be an administrator to view this
return show_error('You must be an administrator to view this page.');
}
else
{
$crud = new grocery_CRUD();
//$crud->set_relation('customerNumber','customers','{contactLastName} {contactFirstName}');
//$crud->display_as('customerNumber','Customer');
$crud->set_table('orders');
$crud->set_theme('datatables');
$crud->set_relation_n_n('disha', 'order_disha', 'disha', 'order_id', 'disha_id', '{disha.disha_id} {disha_name}','priority');
...
$crud->set_subject('Order');
/*set rules*/
$crud->set_rules('email', 'Email', 'trim|valid_email');
$crud->set_rules('price_extra', 'Price Extra', 'decimal');
$crud->display_as('function_address','Function Address')
->display_as('contact_person','Contact Person')
->display_as('contact_no_1','Phone 1')->display_as('contact_no_2','Phone 2')->display_as('contact_no_3','Phone 3')
....
->display_as('disha','Set A')->display_as('dishb','Set B')->display_as('dishc','Set C')->display_as('dishd','Set D')
->display_as('dishe','Set E')->display_as('alacart','Alacart');
$crud->callback_field('function_time_selector',array($this,'functime_callback'));
$crud->callback_field('price_extra',array($this,'price_extra_callback'));
$crud->callback_field('function_purpose',array($this,'purpose_callback'));
$crud->callback_column('function_date',array($this,'_date_callback'));
$crud->columns('function_address','contact_person','contact_no_1','contact_no_2','contact_no_3','email','fax','price','function_date','remark');
$crud->callback_field('price-dd',array($this,'price_callback'));
if($crud->getState() == 'edit' || $crud->getState() == 'add'){
$crud->field_type('function_time', 'hidden', 0);
$crud->fields('function_address','contact_person','contact_no_1','contact_no_2','contact_no_3','fax',
'email','function_date', 'function_time', 'function_time_selector', 'function_purpose', 'purpose_other','pax', 'deposit', 'price-dd',
'price','price_extra', 'remark', 'disha', 'dishb', 'dishc', 'dishd', 'dishe', 'alacart',
'staff_chef_1','staff_chef_1_ic','staff_chef_1_salary',
'staff_chef_2','staff_chef_2_ic','staff_chef_2_salary',
...
'staff_waiter_15','staff_waiter_15_ic','staff_waiter_15_salary'
);
$crud->callback_field('function_time',array($this,'set_functiontime_session_callback'));
}else{
$crud->fields('function_address','contact_person','contact_no_1','contact_no_2','contact_no_3','fax',
'email','function_date', 'function_time', 'function_purpose', 'purpose_other','pax', 'deposit', 'price-dd', 'price',
'price_extra', 'remark', 'disha', 'dishb', 'dishc', 'dishd', 'dishe', 'alacart',
'staff_chef_1','staff_chef_1_ic','staff_chef_1_salary',
...
'staff_waiter_15','staff_waiter_15_ic','staff_waiter_15_salary'
);
}
$crud->order_by('function_date','desc');
//$crud->callback_update(array($this,'updatestaff_callback'));
/*use for Page Title*/
$this->state = $crud->getState();
$this->load->vars( array( 'html_title' => $this->state." order") );
$crud->unset_print();
$crud->callback_before_update(array($this,'update_functiontime_callback'));
$crud->callback_before_insert(array($this,'add_functiontime_callback'));
$output = $crud->render();
$this->_example_output($output);
}
}
function price_callback($value = '', $primary_key = null)
{
print_r($primary_key);
if($this->state == "read"){
return '<div id="field-price" class="readonly_label">'.$value.'</div>';
}else{
return '
<select id="field-price" name="price">
<option value="24.80" '.($value == 24.80 ? "selected" : "").'>Set A - RM24.80</option>
<option value="25.80" '.($value == 25.80 ? "selected" : "").'>Set B - RM25.80</option>
<option value="28.80" '.($value == 28.80 ? "selected" : "").'>Set C - RM28.80</option>
<option value="30.80" '.($value == 30.80 ? "selected" : "").'>Set D - RM30.80</option>
<option value="26.80" '.($value == 26.80 ? "selected" : "").'>Set E - RM26.80</option>
<option value="" '.($value == "" ? "selected" : "").'>Other</option>
</select>
';
}
}
?>
in my price_callback(), i manage to print the primary_key value.
but what i want to achieve is getting the price value fm db and match it with the option value in the dropdown list so that it will display the option value as selected, based on the value in db table and it should happen when I enter Edit record mode. what should i do to get the price value from the db ?
hope this code will give clearer pic of my question.