我有以下表单,它将表单中的每个字段通过电子邮件发送给某人。但是,我希望将这些字段存储到数据库中,并将每个订单链接到销售代表(我已经设置了),我是否应该为 order_details 创建另一个表来存储它。皮斯帮助
最佳答案
这完全取决于您想要如何构建数据。没有 Elixir 的解决方案。但我会做三张 table 。 SALES_REPRESENTATIVE、ORDER 和 ORDER_DETAILS。销售代表有订单,订单有订单详细信息。
所以根据您的输入。
如果您有一个包含产品定义的表格,则可能有一种名为“可口可乐”的产品和另一种名为“芬达”的产品及其单价。
订单详细信息表可以包含指向产品表并指定数量的链接。
订单表将包含指向该订单的订单详细信息的链接,例如还有订购日期。
然后,销售代表可以获得与其相关的所有订单的链接。
具体例子:
PRODUCTS table
Id Name Price in $
1 Coca-cola 1.00
2 Fanta 1.10
ORDER_DETAILS
Id Order_Id Product_Id Quantity
1 1 1 10 // meaning this order detail is 10 Coca-cola's
2 1 2 20 // meaning this order detail is 20 Fanta's (because the tast is better :))
3 2 2 10 // meaning this order detail is 10 Fanta's
//Here Order_id is a foreign key to the Column Id of Table ORDERS
//And Product_id is a foreign key to the Column Id of the Table PRODUCTS
ORDERS
Id Sales_Representative_Id Order_Date
1 2 10/17/2014 // Order one made by Luke on 17th october 2014
2 1 10/19/2014 // Order two made by Anna on 19th october 2014
//Here Sales_Representative_id is a foreign key to the Column Id of Table SALES_REPRESENTATIVES
SALES_REPRESENTATIVES
Id Name
1 Anna
2 Luke
关于php - 将信息数组传递到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26157158/