1 回答

TA貢獻1802條經驗 獲得超4個贊
它得到未定義的索引,因為在您的上傳功能上,如果您只上傳單個文件,那么它只會生成單個上傳數據,因此 the $files[0]or$files[1]數組將是未定義的,并且松散相等或松散非相等條件將失敗。
為了讓你的邏輯工作,你可以使用empty檢查:
if (!empty($files[0]) && empty($files[1])) {
$this->db->select('id,picture_id');
$this->db->from($this->project_tbl);
$this->db->where('id', $id);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$this->db->where('id', $query->row()->picture_id);
$this->db->update($this->project_core_documents, $files[0]);
}
} else if (!empty($files[1]) && empty($files[0])) {
$this->db->select('id,detailed_report_id');
$this->db->from($this->project_tbl);
$this->db->where('id', $id);
$query = $this->db->get();
if ($query->num_rows() > 0) {
$this->db->where('id', $query->row()->detailed_report_id);
$this->db->update($this->project_core_documents, $files[1]);
}
} else {
//both files
}
if即使其中一個$files具有未定義的索引,這也會執行該塊。但是你應該注意,else如果兩者$files都不為空,并且兩者都$files為空,則該語句將被執行
- 1 回答
- 0 關注
- 150 瀏覽
添加回答
舉報