Welcome Guest, Not a member yet? Register   Sign In
Getting next ID before insert
#5

[eluser]Felipe Deitos[/eluser]
Ckirk: I guess this is wrong, example: if your last recorded id is 570 but u got the 571 and 572 deleted the next id would be 573, but in your code it will be 571.

Sotoz: Thats what i am doing i wrote some functions yesterday and make it work really great, take a look:
Code:
function create(){
  
  $info = array(
   'idcategoria' => $this->input->post('ipt_categoria'),
   'codigo' => $this->input->post('ipt_codigo'),
   'nome' => $this->input->post('ipt_nome'),
   'descricao' => $this->input->post('ipt_descricao'),
   'esp_tecnica' => $this->input->post('ipt_esp_tecnica'),
   'ativo' => $this->input->post('ipt_ativo'),
   'destaque' => $this->input->post('ipt_destaque')
  );
  
  
  $query = $this->db->insert('produtos', $info);
  //Could make one if $query
  $insert_id = $this->db->insert_id();
  
  $files = $_FILES;
  $erros = array();
  $imagens = array();
  foreach($files as $field => $file){
   if(!empty($file['name'])){
    $upload = $this->upload_imagem($insert_id, $field); //upload image function
    if(isset($upload['error'])){
     $erros[$field] = $upload['error'];
    }else{
     $imagens[$field] = $upload['imagem'];
    }
   }
  }
  
  if(!empty($erros)){
   foreach($erros as $key => $erro){
   // doing it now, there are 5 images so if the 4 give anything wrong i delete the others and delete the record too.
   }
  }else{
   $this->db->where('id', $insert_id);
   $this->db->update('produtos', $imagens);
  }
}

Thanks for the answers guys, really appreciated!

Cheers!


Messages In This Thread
Getting next ID before insert - by El Forum - 06-24-2013, 07:16 AM
Getting next ID before insert - by El Forum - 06-24-2013, 07:44 AM
Getting next ID before insert - by El Forum - 06-24-2013, 11:41 AM
Getting next ID before insert - by El Forum - 06-24-2013, 01:35 PM
Getting next ID before insert - by El Forum - 06-25-2013, 05:29 AM
Getting next ID before insert - by El Forum - 06-25-2013, 05:34 AM
Getting next ID before insert - by El Forum - 06-25-2013, 06:04 AM
Getting next ID before insert - by El Forum - 06-25-2013, 06:23 AM
Getting next ID before insert - by El Forum - 06-25-2013, 06:25 AM
Getting next ID before insert - by El Forum - 06-25-2013, 09:50 AM
Getting next ID before insert - by El Forum - 06-26-2013, 12:10 AM
Getting next ID before insert - by El Forum - 06-26-2013, 06:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB