gpt4 book ai didi

php - 将购物车订单保存到数据库的最佳方法是什么?将项目保存为一行或多行中的数组?

转载 作者:行者123 更新时间:2023-11-29 10:41:29 25 4
gpt4 key购买 nike

只是在这里寻求建议。我有一个购物车网站。我将发布我的 php 来接收这些项目并将其打印出来。但是,我希望将这些订单存储在我的数据库中。我应该...我可以...在一个单元格的一行下保存多个项目吗?

{"114":{"id":"114","name":"Raskals Lemon","quantity":1,"price":15,"weight":1,"shopid":"1","shopname":"MMD","type":"Sativa","size":"---","strain":"Sativa","thc":"---","subtype":"Flower"},"117":{"id":"117","name":"Nectarine","quantity":1,"price":15,"weight":1,"shopid":"1","shopname":"MMD","type":"Sativa","size":"---","strain":"Sativa","thc":"---","subtype":"Flower "}}

或者将所有项目及其详细信息保存为多行并使用“订单号”之类的内容在将来的查询中将这些行连接在一起会更好吗?

这是基本的 php,如果它与问题完全相关的话。

$order = '';

for($i=1; $i < $content['itemCount'] + 1; $i++) {

$item_name = 'item_name_'.$i;
$item_quantity = 'item_quantity_'.$i;
$item_price = 'item_price_'.$i;
$item_weight = 'item_weight_'.$i;
$item_id = 'item_id_'.$i;
$item_shop = 'item_shopid_'.$i;
$item_type = 'item_type_'.$i;
$item_shopname = 'item_shopname_'.$i;
$item_size = 'item_size_'.$i;
$item_strain = 'item_strain_'.$i;
$item_subtype = 'item_subtype_'.$i;






$order .= <<<EOT



<li>

<h2 style="font-size:14px;">$content[$item_name]</h2>
<p style="text-indent:5px;padding-top:5px;"><strong>Quantity:</strong> $content[$item_quantity]</p>
<p style="text-indent:5px;"><strong>Grams:</strong> $content[$item_weight]</p>
<p style="text-indent:5px;"><strong>Catagory:</strong> $content[$item_type]</p>
<p style="text-indent:5px;"><strong>Sub Catagory:</strong> $content[$item_subtype]</p>
<p style="text-indent:5px;"><strong>Size:</strong> $content[$item_size]</p>
<p style="text-indent:5px;"><strong>Strain:</strong> $content[$item_strain]</p>




<p class="ui-li-aside"><strong>$currency$content[$item_price].00</strong></p>
<span class="ui-li-count">$i</span>

</li>








EOT;
}

最佳答案

我在这里看到两个表(我认为第三个表是您已经拥有的表):

tables structure

  • order 表是存储每个订单的地方。一份订单 = 该表中的一条记录。您可以在此处查看一些与订单相关的详细信息,例如送货地址、送货方式等。
  • order_item 表是存储每个订购商品的位置。这具有多对一的关系。一份订单中订购了许多商品。您可以在此处查看与商品相关的详细信息,例如给定商品的数量、尺寸和其他信息。

关于php - 将购物车订单保存到数据库的最佳方法是什么?将项目保存为一行或多行中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45388722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com