Is it possible to retrieve values from database as an array and save the same values back to the database?
For example, In my table1 it returns an array:
array(1) {
[0]=> string(5) "test1"
}
I wanted to save test1 back to my database.
Codes:
View
<?php //for viewing data
foreach ($users as $user) {
echo $user->empID;
echo '<br>';
}
?>
<?php //for inserting data
foreach ($users as $row) {
$rec_users[] = $row->empID;
}
echo form_multiselect('empRequired[]', $rec_users, $rec_users, array('class' => 'chosen-select', 'multiple style' => 'width:785px;'));
?>
Controller
$lid = $this->admin_model->getID();
foreach ($lid as $id) {
$last_id = $id['projectID'];
$data['users'] = $this->admin_model->getUsers($last_id);
}
$this->load->view('admin/projects/rec-employee', $data);
$recommended = $this->input->post('empRequired');
foreach ($recommended as $row) {
$data1 = array(
'projectID' => $last_id,
'username' => $row
);
$this->admin_model->insertRecEmp($data1);
}
Model
public function insertRecEmp($data){
return $this->db->insert('projectemp', $data);
}
Table 1: primary key
+--------+
|username|
+--------+
| test1 |
+--------+
Table 2: foreign key
+--------+----------+
|empID |projectID |
+--------+----------+
| test1 | |
+--------+----------+
I want the test1 in the dropdown to be saved in my database, however when I click next, it results to
Instead of test1, it's returning 0.

