php - INSERT INTO SELECT with VALUES in one query -


bit new mysql , php - have following code create new record in multiple tables have setup need merge following code somehow creates separate rows instead of 1 record

$sql .=("insert orders (customer_id) select customer_id  customer_details;");      foreach($result $item){ $mysql_desc = $item['product_description']; $mysql_mode = $item['delivery_mode']; $mysql_cost = $item['course_cost']; $sql .=("insert orders(product_description, delivery_mode, course_cost) values('$mysql_desc', '$mysql_mode', '$mysql_cost');"); } 

the result i'm getting:

enter image description here

based on data assume want insert customer id , values php same record. in case need combine them same insert ... select ... statement:

$sql .=("insert orders(customer_id, product_description, delivery_mode, course_cost) select customer_id, '$mysql_desc', '$mysql_mode', '$mysql_cost' customer_details;"); 

couple of things note:

  1. this insert ... select ... statement insert same records customers in customer details table. i'm not sure if ultimate goal.

  2. pls consider advices made in comments regarding old mysql api , use of prepared statements.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -