i have ajax function in controller:
public function add_display_row($shape, $rows) { $newrecord = array( 'work_id' => '', 'section_id' => (int)$rows + 1, 'shape' => $shape ); //insert new record after last $newro = array(); for( $c=1; $c<6; $c++){ $newrecord['ordinal'] = $c; $newrecord['size_id'] = $this->work_model->get_size_from_specs($shape, $c); $insnew = $this->work_model->save_new_featured_shape($newrecord); $newrecord['item_id'] = $insnew; array_push($newro, $newrecord); } print_r($newro); } and in model
public function save_new_featured_shape($record) { $this->db->trans_begin(); $this->db->insert('work_featured', $record); if ($this->db->trans_status() === false) { $this->db->trans_rollback(); return false; } else { $this->db->trans_commit(); $insert_id = $this->db->insert_id(); return $insert_id; } } after 5 records inserted, returning array caller , item_id (which should insert id of each) equals 0.
i need insert_id returned build dom element insert dom.
can see why zero?
modify add_display_row following.
public function add_display_row($shape, $rows) { //$this->load->model('work_model'); $newrecord = array( 'work_id' => '', 'section_id' => (int)$rows + 1, 'shape' => $shape ); $new_arr=array(); //insert new record after last $newro = array(); for( $c=1; $c<6; $c++){ $newrecord['ordinal'] = $c; $newrecord['size_id'] = $this->work_model->get_size_from_specs($shape, $c); $insnew = $this->save_new_featured_shape($newrecord); $new_arr['item_id'] = $insnew; $new_arr_arr=array_merge($newrecord,$new_arr); array_push($newro, $new_arr_arr); } echo "<pre>"; print_r($newro); } and model function following.
public function save_new_featured_shape($record) { $this->db->trans_begin(); $this->db->insert('work_featured', $record); $insert_id = $this->db->insert_id(); if ($this->db->trans_status() === false) { $this->db->trans_rollback(); return false; } else { $this->db->trans_commit(); return $insert_id; } }
Comments
Post a Comment