У меня есть таблица с двумя столбцами: product_name и product_qty с несколькими строками
Я хочу выводить как:
product_name (product_qty) .........
как этот
product_one (2), product_two (4), product_three (1)
Я пытаюсь этим методом:
require 'config.php';
$grand_total = 0;
$items = array();
$qty = array();
$allItems ='';
$stmt = $conn->prepare("SELECT * FROM cart");
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()){
$grand_total +=$row['total_price'];
$items[] = $row['product_name'];
$qty[] = $row['qty'];
}
$array = array_combine($items, $qty);
foreach ($array as $key => $value) {
$allItems .= $key."(".$value."), ";
}
Иполучить вывод в виде: product_one (2), product_two (4), product_three (1),
но я не хочу запятую в прошлом ......