<label style="width: 150px; float: left">Co Auditor</label>
<select name="co_auditor_nip[]" multiple = 'multiple' size=6>
<?php
foreach ($co_auditor_nip->result() as $row)
{
echo '<option value="'.$row->nip.'"';
if($co_auditor_nip_choosen == $row->nip)
{
echo 'selected="selected"';
}
echo' >'.$row->nama.'</option>';
}
?>
</select><br>
之后我想用php codeigniter将值插入数据库,如下所示:
$co_auditor_nips['co_auditor_nip'] = addslashes($this->input->post('co_auditor_nip'));
$this->db->query("INSERT INTO r_audit VALUES (' ', '$company_code', '$company_name', '$branch_code',
'$branch_name','$business_unit', '$lead_auditor_nip', '$lead_auditor', '$co_auditor_nips', '$co_auditor',
'$periode_audit_from','$periode_audit_to', '$tanggal_audit_from', '$tanggal_audit_to', '$auditee', '$auditee_jabatan',
'$auditee_email',
'$auditee_2','$auditee_2_jabatan' ,'$auditee_2_email', '$cc_email', 'started', '1')");
但是我在数据库列上的结果只是Array(文本数组),帮我获取所有值,谢谢!
答案 0 :(得分:0)
您希望将数组插入到数据库中,因此在检索时使用json_encode()
并在检索时使用json_decode()
会很好。你可以这样做
$co_auditor_nips['co_auditor_nip'] = json_encode($this->input->post('co_auditor_nip'));
或者你可以在检索时使用implode()' while inserting and
explode()`,像这样,
$co_auditor_nips['co_auditor_nip'] = implode(",",$this->input->post('co_auditor_nip'));
要explode
来自DB的值,您可以这样做
$str = "value from database which is in comma-separated format";
print_r (explode(",",$str));