I am trying to insert data into a table, and the data is drawn from another table. At the moment my code looks like this:
$result3 = mysql_query('SELECT order_no
FROM orders
WHERE ord_date = "' . ($_POST["ord_date"]) . '"');
while($row=mysql_fetch_array($result3)){ $order=$row['order_no'];}
$result4 = mysql_query('SELECT door_product_no
FROM estimateDescribesDoorProduct
WHERE estimate_no = "' . ($_GET["estimate_no"]) . '"');
while($row=mysql_fetch_array($result4)){ $door=$row['door_product_no'];}
$result5 = mysql_query('SELECT quantity
FROM estimateDescribesDoorProduct
WHERE estimate_no = "' . ($_GET["estimate_no"]) . '"');
while($row=mysql_fetch_array($result5)){ $dquantity=$row['quantity'];}
$sql2="INSERT INTO orderConsistsOfDoor (order_no, door_product_no, product_quantity)
VALUES ('$order','$door','$dquantity')";
I used this method yesterday thanks to some advice on this site. My problem today is that I need to insert multiple rows. The tables 'orderConsistsOfDoor' and 'estimateDescribesDoorProduct' are identical except that for the first column (order_no/estimate_no). Basically if an estimate (or order) consists of e.g. 3 products, then there will be 3 rows in the table with that estimate_no (but different product_no and quantity).
I think that the code I have will only insert one row into orderConsistsOfDoor, but I need it to insert every row where the estimate_no is ($_GET["estimate_no"]). I think this can be done with foreach or something but I've never used this and don't know how it works.
Can somebody help me?