【发布时间】:2012-10-17 21:58:00
【问题描述】:
我正在尝试从一组输入字段中获取数据并将它们写入数据库。我以前从未使用过数组,但这是我拥有的代码。它基于如果它只是一个输入值我会做什么。我知道这是错误的,但我不知道下一步该尝试什么。有任何想法吗?谢谢。
//view
<input type="text" name="assignments[]">
<input type="text" name="hours[]">
<input type="text" name="assignments[]">
<input type="text" name="hours[]">
<input type="text" name="assignments[]">
<input type="text" name="hours[]">
<input type="text" name="assignments[]">
<input type="text" name="hours[]">
<input type="text" name="assignments[]">
<input type="text" name="hours[]">
//controller
$assignments = $this->input->post('assignments', TRUE);
$hours = $this->input->post('hours', TRUE);
$this->load->model('create', 'create_model');
$this->create_model->create_projects($assignments, $hours);
//model
public function create_projects($assignments, $hours) {
$data = array(
'assignments' => $assignments,
'hours' => $hours,
);
$this->db->insert('projects', $data);
}
【问题讨论】:
-
这取决于您希望数据在数据库中的表示方式。例如,您不能将数组存储在文本字段中,除非您对其进行序列化(我怀疑这是您现在所做的)。
标签: database arrays codeigniter