无法传递 SQL 数据以在 codeigniter 中查看
Trouble passing SQL data to view in codeigniter
我有一个表格,可以让人们输入数据,然后上传预设图片。我想将该图片标记为 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);
}
}
任何您想在视图上显示的内容,都必须传递给它。
当您设置 $data
时,您错过了添加 $query
。
控制器:
我知道 $query = $this->trailer_model->select_last_id();
return 只是一个 ID,所以:
$data['last_id'] = $query;
但是如果 $query = $this->trailer_model->select_last_id();
不 return 只是一个 ID,而是一个数组或其他东西,你应该包括到 return模型方法中的 ID。实际上,了解 $this->trailer_model->select_last_id();
是什么 returning 是至关重要的。
查看:
echo $last_id;
-> 必须回显最后一个 ID,如果 select_last_id()
方法来自您的模型 return 它必须 return.
我有一个表格,可以让人们输入数据,然后上传预设图片。我想将该图片标记为 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);
}
}
任何您想在视图上显示的内容,都必须传递给它。
当您设置 $data
时,您错过了添加 $query
。
控制器:
我知道 $query = $this->trailer_model->select_last_id();
return 只是一个 ID,所以:
$data['last_id'] = $query;
但是如果 $query = $this->trailer_model->select_last_id();
不 return 只是一个 ID,而是一个数组或其他东西,你应该包括到 return模型方法中的 ID。实际上,了解 $this->trailer_model->select_last_id();
是什么 returning 是至关重要的。
查看:
echo $last_id;
-> 必须回显最后一个 ID,如果 select_last_id()
方法来自您的模型 return 它必须 return.