I have form in Code Igniter and I want to use helper form_dropdown(). In order to do it I have to prepare associative array like this:
$options = array(
'small' => 'Samsung',
'med' => 'Apple',
'large' => 'HTC',
'xlarge' => 'Nokia',
);
But in this view this data are transferred from controller, which are taken from model, of course.
$this->db->select('id');
$query = $this->db->get('ci_table1');
if ($query->num_rows() > 0 )
{
foreach ($query->result() as $row)
{
$data[] = $row;
};
};
$id_data['id'] = $data;
$this->load->view('update_record_view', $id_data);
So, on the side of view I have the foreach-loop:
foreach ($id as $row)
{
// this I want to construct associative array
}
Question is follow: how to create associative array at my case dynamically?
I don’t understand your code. But maybe this is what you are looking for.
and: