0

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,您将看到一个带有发票的详细信息页面,上面写着

  1. 客户编号 10
  2. 姓名:法比奥
  3. 电子邮件:fab@fab.com
  4. 运送到:办公室,123 main st...
  5. 账单:签证,acct#等...
4

1 回答 1

0
$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();
}
于 2012-10-14T21:27:18.867 回答