我尝试使用带有库推车的CodeIgniter应用程序创建在线商店,但是在按类别ID显示数据时遇到问题如何解决这个问题?
实施例
存储A
ID | Name | Qty | Store |
---- | -------------- | ------ | --------- |
1 | Nokia 1 | 1 | Store A |
2 | Samsung xxx | 1 | Store A |
3 | Nokia 2 | 3 | Store A |
商店B
ID | Name | Qty | Store |
---- | -------------- | ------ | --------- |
4 | Nokia 6 | 1 | Store B |
5 | Samsung xx | 1 | Store B |
商店C
ID | Name | Qty | Store |
---- | -------------- | ------ | --------- |
6 | Nokia 9 | 1 | Store C |
添加到购物车,控制器
function add_to_rent($id_product) {
$produk = $this->product_model->get_id($id_product);
$data = array(
'id' => $produk->id_product,
'name' => $produk->name_product,
'qty' => 1,
'store' => $produk->id_outlet
);
$this->cart->insert($data);
redirect($this->agent->referrer());
}
查看购物车
<?php
foreach ($this->cart->contents() as $product){
?>
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name product</th>
<th>Qty</th>
<th>Store</th>
/tr>
</thead>
<tbody>
<tr>
<td><?php echo $product['id'];?></td>
<td><?php echo $product['name'];?></td>
<td><?php echo $product['qty'];?></td>
<td><?php echo $product['store'];?></td>
</tr>
</tbody>
</table>
<?php } ?>