I'm wondering if someone can help me out. I have a form_dropdown which is filled with options from the database. I want to show the default value which the user selected while inserting a record, but can't figure out how to do it without adding that to the database This is Model
function get_type()
{
$results = $this->db->select('t_id, t_name')->from('account_type')->get()->result();
$t_id = array('-SELECT-');
$t_name = array('-SELECT-');
for ($i = 0; $i < count($results); $i++)
{
array_push($t_id, $results[$i]->t_id);
array_push($t_name, $results[$i]->t_name);
}
return $type_result = array_combine($t_id, $t_name);
}
function get_account_record($a_id)
{
$this->db->where('a_id', $a_id);
$this->db->from('account_info');
$query = $this->db->get();
return $query->result();
}
This is the Controller
function update($a_id)
{
$data['a_id'] = $a_id;
$data['type'] = $this->sf_model->get_type();
$data['view'] = $this->sf_model->get_account_record($a_id);
$this->form_validation->set_rules('a_name', 'Account Name', 'trim|required|xss_clean|callback_alpha_only_space');
$this->form_validation->set_rules('a_web', 'Website', 'trim|required|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('viewUpdate', $data);
}
else
{
$data = array(
'a_id' => $this->input->post('a_id'),
'a_name' => $this->input->post('a_name'),
'a_website' => $this->input->post('a_web'),
't_id' => $this->input->post('a_type'),
'a_billingStreet' => $this->input->post('a_billingStreet'),
'a_billingCountry' => $this->input->post('a_billingCountry'),
'a_mobile' => $this->input->post('a_mobile')
);
$this->db->where('a_id',$_POST['a_id']);
$this->db->update('account_info', $data);
redirect('salesforce' . $a_id);
}
}
this is the view of dropdown function TYPE only
<?php
$attributes = 'class = "form-control" id = "a_type"';
echo form_dropdown('a_type',$type,set_value('a_type'),$attributes);?>
<span class="text-danger"><?php echo form_error('a_type'); ?></span>
?>
$selected =''. Then, while looping through the results, if the user's value is equal to the dropdown value$selected = 'selected'