Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

349
Views
Copie datos a otra tabla usando la consulta sql y model codeigniter

Soy nuevo en Codeigniter, estoy haciendo algo como un elemento en el sistema de carrito, usando una tabla temporal y una tabla principal. En mi caso ahora, quiero copiar datos de la tabla temporal (carrito) en mi mesa principal... pero Estoy usando la última identificación de inserción para obtener la identificación del número de pedido. aquí están mis tablas SQL

 Order Order Detail Cart ID | DATE ID | Order_ID | Item_ID ID | Item_ID 1 | 1 2 | 2

y aquí está mi controlador de guardado

 function save() { extract($_POST); $date = date('Ym-d') $data = array('date' => $date); $this->db->insert('order',$data); $order_id = $this->db->insert_id(); //This is the copy process from Table Cart to Table Order Detail $row = $this->db->query('SELECT Item_ID from cart')->row(); foreach($row as $key) { // I dont know what to loop.... } $data1 = array('order_id' => $id, 'item_id'=> $key->item_id); $this->db->insert('order_detail',$data1); $this->db->delete('cart'); }

ya traté de poner $data1 dentro de mi bucle, pero no funciona... los datos no se imprimirán... y traté de usar SQL Query normal

 $this->db->query('INSERT INTO order_detail (item_id) SELECT item_id FROM cart');

pero necesito la variable $order_id dentro de la consulta SQL normal. Hay alguna forma de hacerlo ? Gracias,..

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

ya resolví mi código... aquí está mi propia solución...

 function save() { extract($_POST); $date = date('Ym-d') $data = array('date' => $date); $this->db->insert('order',$data); $order_id = $this->db->insert_id(); //This is the copy process from Table Cart to Table Order Detail $this->db->query('INSERT INTO order_detail (item_id) SELECT item_id from cart'); // End Copy Data // Then Update null order_id where order_id = 0 $this->db->query('UPDATE order_detail SET order_id='.$id.' WHERE order_id=0'); //End Update }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!