I have a table named order
where there is set a column name list
TABLE list
id | list | price | date
---------------------------------------
1 | Cigar | 5.00 | 2016-06-30
2 | Beer | 6.00 | 2016-06-30
3 | Whiskey | 20.00 | 2016-06-30
4 | Bacon | 10.00 | 2016-06-30
I'd like to insert the list
into another table named confirmation
in a way that all of them could be in a same row! However, it doesn't work and is inserting in many rows!
The way I want
TABLE confirmation
id | theorder
--------------------------------
1 | Cigar, Beer, Whiskey, Bacon
The way is showing
TABLE confirmation
id | theorder
--------------
1 | Cigar,
2 | Beer,
3 | Whiskey,
4 | Bacon,
Here is the code: I'm working with foreach!
$sql = "SELECT list FROM order";
$result = $conn->query($sql);
$getList = $result->fetchAll(PDO::FETCH_ASSOC);
foreach($getOrder as $order) {
$products = $order['theorder'] . ', ';
$sql = "INSERT INTO confirmation (theorder) VALUES ('$products')";
$result = $conn->query($sql);
}