[英]Point of Sale System
I am developing an web-based Point-of-Sale system for a client.我正在为客户开发基于 Web 的销售点系统。 The system is nearly finished but I am experiencing a couple of small issues.系统即将完成,但我遇到了一些小问题。
The order items are stored in a array, which is stored in a session variable, which looks like this:订单项存储在一个数组中,该数组存储在会话变量中,如下所示:
[items] => Array
(
[0] => Array
(
[id] => 15
)
[2] => Array
(
[id] => 16
)
[3] => Array
(
[id] => 15
)
[4] => Array
(
[id] => 16
)
)
This code displays the items:此代码显示项目:
Note: For each ID in the $items variable I do a lookup in the database to extract addition information about that item.注意:对于 $items 变量中的每个 ID,我都会在数据库中进行查找以提取有关该项目的附加信息。
foreach($items as $item) {
$cc++;
$id = $item['id'];
$item_db = $db->query("SELECT * FROM inventory WHERE id='$id' LIMIT 1")->fetch_array();
$subtotal += $item_db['price'];
$quantity = 1;
if(!empty($item_db['name'])) {
?>
<tr style="visibility: hidden">
<td> <a href="?deleteItem=<?=$cc?>" style="color:#000"><i class="fa fa-trash"></i></a> </td>
<td> <?=$item_db['name']?> </td>
<td> <?=$quantity?> </td>
<td> <?=$currency?><?=round($item_db['price'],2)?> </td>
</tr>
<?
}
}
?>
How would I group the items so instead of displaying the same item multiple times with quantity of 1, group the entries and display the total quantity of all entries (which are the same)?我将如何对项目进行分组,而不是多次显示数量为 1 的同一项目,而是将条目分组并显示所有条目的总数(相同)?
For example, instead of:例如,而不是:
Laptop 1
Laptop 1
I want to display:我想显示:
Laptop 2
Now you have the id of products as keys with the count of products as value.现在您将产品的 id 作为键,将产品的数量作为值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.