I have a multiple select box in my view, I am using the Codeigniter framework. I want to insert the values that consist of ID's in my multiple selection box.
I get the values from my multiple select in controller, using this:
$diagnosis = $this->input->post('tdiagnosis');
var_dump($diagnosis);
when I var_dump the value of $diagnosis
I get this:
array(2) {
[0]=>
string(1) "1"
[1]=>
string(1) "2"
}
I want to loop these values to be inserted one by one into my database, here is what I've done:
public function finish_checkup($patient_id,$queue_id,$checkup_id,$clinic_id) {
$diagnosis = $this->input->post('tdiagnosis');
for($i = 0;$i < count($diagnosis); $i++) {
$data4 = array (
'diagnosis' => $diagnosis[i],
'check_up_id' => $checkup_id
);
$insert = $this->Mymodel->savetodb($data4);
}
}
why do I get this error?
Severity: Notice
Message: Use of undefined constant i - assumed 'i'
Change it:
'diagnosis' => $diagnosis[i],
to
'diagnosis' => $diagnosis[$i],
you forget to add $
with the variable i
, that's why the notice Use of undefined constant i - assumed 'i'
public function finish_checkup($patient_id,$queue_id,$checkup_id,$clinic_id) {
$diagnosis = $this->input->post('tdiagnosis');
$data['check_up_id'] = $check_up_id;
foreach ($diagnosis as $diagnos) {
$data['diagnosis'] = $diagnos;
$insert = $this->Mymodel->savetodb($data);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.