我有一个表单,我用它来允许人们输入数据然后上传预设图片。我想将该图片标记为form_id。我可以运行LAST_INSERT_ID()查询并在我在视图中插入表单后显示它,但我似乎无法在其他任何地方回显该信息。我需要在$ update查询后运行select_last_id的查询,否则ID号将关闭。任何人都可以帮助我将行的值传递给我的视图吗?这是我的控制器的代码。
function inspection() {
if($this->input->post('submit')) {
$array = array(
'trlr_num' => $this->input->post('trlr_num'),
'seal' => $this->input->post('seal'),
'damaged' => $this->input->post('damaged'),
'truck_num' => $this->input->post('truck_num'),
'driver_name' => $this->input->post('driver_name'),
'car_code' => $this->input->post('car_code'),
'origin' => $this->input->post('origin'),
'lic_plate' => $this->input->post('lic_plate'),
'del_note' => $this->input->post('del_note'),
'live_drop' => $this->input->post('live_drop'),
'temp' => $this->input->post('temp'),
'level' => $this->input->post('level'),
'ship_num' => $this->input->post('ship_num'),
'trlr_stat' => $this->input->post('trlr_stat'),
'comment' => $this->input->post('comment')
);
$update = $this->trailer_model->insert_form($array);
$query = $this->trailer_model->select_last_id();
$result =& $query->result_array();
$this->table->set_heading('ID');
$data['table'] = $this->table->generate_table($result);
unset($query,$result);
}
$level = $this->trailer_model->select_fuel_level();
$result = $level->result_array();
$data['options'] = array();
foreach($result as $key => $row) {
$data['options'][$row['level']] = $row['level'];
}
unset($query,$result,$key,$row);
$data['label_display'] = 'Fuel Level';
$data['field_name'] = 'level';
$status = $this->trailer_model->select_trailer_type();
$result = $status->result_array();
$data['options1'] = array();
foreach($result as $key => $row) {
$data['options1'][$row['trlr_stat']] = $row['trlr_stat'];
}
unset($query,$result,$key,$row);
$data['label_display1'] = 'Trailer Status';
$data['field_name1'] = 'trlr_stat';
$data['page_title'] = 'Trailer Inspection';
$data['main_content'] = 'dlx/inspection/trailer_inspection_view';
return $this->load->view('includes/template',$data);
}
}
答案 0 :(得分:0)
您要在视图上显示的任何内容,都必须传递给它。
当您设置$data
时,您错过了向其添加$query
。
<强>控制器:强>
我知道$query = $this->trailer_model->select_last_id();
只返回一个ID,所以:
$data['last_id'] = $query;
但如果$query = $this->trailer_model->select_last_id();
不只返回一个ID,而是一个数组或其他内容,则应包括在模型方法中返回ID。实际上,了解$this->trailer_model->select_last_id();
正在返回的内容至关重要。
查看:强>
echo $last_id;
- &gt;如果模型中的select_last_id()
方法返回它必须返回的内容,则必须回显最后一个ID。