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:
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:
this
insert ... select ...
statement insert same records customers in customer details table. i'm not sure if ultimate goal.pls consider advices made in comments regarding old mysql api , use of prepared statements.
Comments
Post a Comment