将信息数组传递到数据库中

时间:2014-10-02 08:37:16

标签: php mysql database forms

我有以下表单,通过电子邮件将表单中的每个字段发送给某人。但是我希望将字段存储到数据库中并将每个订单链接到销售代表(我已经设置)我是否应该为order_details创建另一个表,例如存储它。 Pease帮助enter image description here

1 个答案:

答案 0 :(得分:0)

这完全取决于您希望如何构建数据。没有银弹解决方案。但我会制作三张桌子。 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
相关问题