codeigniter - Only the first IF statement out of 3 is executed within a PHP loop -
codeigniter - Only the first IF statement out of 3 is executed within a PHP loop -
the next code uploads multiple images no problem. however, i'm trying update field in table based on iteration loop in. problem: if statement seems not work when looped. i.e. adds first file_name database.
anyone see i'm doing wrong here? much appreciated if so!!!
for ($i = 1; $i < 4; $i++) { /* handle file upload */ $upload = $this->upload->do_upload('image' . $i); /* file failed upload - go on */ if ($upload === false) continue; /* info file */ $data = $this->upload->data(); $uploadedfiles[$i] = $data; if ($i == 1) { $filenames1 = array( 'product_image_front' => $data['file_name'], ); $this->db->where('id', $this->db->insert_id()); $this->db->update('products', $filenames1); } if ($i == 2) { $filenames2 = array( 'product_image_back' => $data['file_name'], ); $this->db->where('id', $this->db->insert_id()); $this->db->update('products', $filenames2); } if ($i == 3) { $filenames3 = array( 'product_image_back' => $data['file_name'], ); $this->db->where('id', $this->db->insert_id()); $this->db->update('products', $filenames3); } }
insert_id - id generated in lastly query.
store in variable before loop.
php codeigniter loops if-statement iteration
Comments
Post a Comment