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
。
现在请注意,我不希望有人写我的代码,但如果你能给我一些链接来阅读,那就太好了,或者一个例子会很棒。请注意,我是在代码点火器上构建的,所以我使用MVC模式。
?-所有这些查找应该在一个模型函数中结构化,还是应该分布在模型中的几个函数中?
return $this->db->get('order_table')->result();
#this would return all the orders in the order table .
在我的view
中,我会预先处理这些结果,并使订单id成为更多详细信息/发票页面的链接。如何将行中的值传递给模型查询以生成正确的详细信息/发票页面?
例如-因此,如果你点击订单251,你会看到一个详细信息页面,上面有一张发票,上面写着
- 客户id 10
- 名称:法比奥
- 电子邮件:fab@fab.com
- 发货地点:办公楼123号
- 账单收件人:visa、acct#等
$this->db->join('customerTable','customerTable.id = orderTable.customer');
$this->db->join('shipToTable', 'orderTable.ship_to = shipToTable.ship_to');
$this->db->join('billToTable', 'billToTable.bill_to = orderTable.bill_to');
$this->db->where('order_id', $orderId);
$result = $this->db->get('order_table');
if($result->num_rows()==1)
{
return $result->result_array();
}