Customer table
///////////////////////////////////////////////////////////
| id[PR] | name | email |
| 10 | fabio | fab@fab.com |
| 11 | james | james@james.com |
Order table
//////////////////////////////////////////////////////////////////
| order_id[PR] | ship_to[FK] | bill_to[FK] | customer[FK] | product, total, etc
| 251 | 3 | 2 | 10 | . . .
Ship to table
//////////////////////////////////////////////////////////////////////
| customer[FK] | ship_to[PR] | label | address | city, state, zip, etc
| 10 | 3 | office | 123 main st | . . .
| 10 | 1 | home | 85 some place st | . . .
Bill to table
///////////////////////////////////////////////////////////////////////////
| customer[FK] | bill_to[PR] | label | account | billing details
| 10 | 2 | visa | AES_CRYPT(temp storage) | . . .
| 10 | 1 | mc | AES_CRYPT(temp storage) | . . .
好的,所以每个客户都可以在他们的帐户中记录多发往地址和多付款方式。当他们下订单时,订单表会存储购物车和会话信息。
我需要生成invoices
如何构造我的查询,以便当我查找订单表时,我可以看到关联表中的行ship to table
和行,bill to table
而不是行的行。id
现在请注意,我不希望任何人编写我的代码,但如果可以的话,请给我一些链接来阅读这将是很棒的,或者一个例子会很棒。请注意我在 codeigniter 上构建,所以我使用 MVC 模式。
? - 所有这些查找应该在 1 个模型函数中构建,还是应该分布在模型中的多个函数中?
return $this->db->get('order_table')->result();
#this would return all the orders in the order table .
在我的情况下,view
我会 foreach 这些结果并使订单 ID 成为指向更多详细信息/发票页面的链接。如何将行中的值传递给模型查询以生成正确的详细信息/发票页面?
例如 - 因此,如果您单击订单 251,您将看到一个带有发票的详细信息页面,上面写着
- 客户编号 10
- 姓名:法比奥
- 电子邮件:fab@fab.com
- 运送到:办公室,123 main st...
- 账单:签证,acct#等...