1 回答

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊
它得到未定義的索引,因?yàn)樵谀纳蟼鞴δ苌?,如果您只上傳單個(gè)文件,那么它只會(huì)生成單個(gè)上傳數(shù)據(jù),因此 the $files[0]or$files[1]數(shù)組將是未定義的,并且松散相等或松散非相等條件將失敗。
為了讓你的邏輯工作,你可以使用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即使其中一個(gè)$files具有未定義的索引,這也會(huì)執(zhí)行該塊。但是你應(yīng)該注意,else如果兩者$files都不為空,并且兩者都$files為空,則該語(yǔ)句將被執(zhí)行
- 1 回答
- 0 關(guān)注
- 144 瀏覽
添加回答
舉報(bào)