如何从不相关的表创建视图

时间:2018-08-18 18:29:15

标签: php codeigniter

click here to view tables

我有三个表,分别用于产品,销售和购买。产品与销售相关,也与购买相关。

如何使用Codeigniter生成如上所示的视图?

'npm' is not recognized as an internal or external command,
operable program or batch file.

1 个答案:

答案 0 :(得分:0)

类似的事情应该起作用。请注意,我使用的是表中所示的情况,因此您应该根据需要进行调整。

$this->db->select('Product.id, Product.Name, Sells.Pid AS Spid, Sells.Items_sold, Sells.Date AS Sells_date');
$this->db->select('Purchased.Pid, Purchased.Items_purchased, Purchased.date AS Purchased_date');
$this->db->from('Product');
$this->db->join('Sells', 'Product.id = Sells.Pid');
$this->db->join('Purchased', 'Product.id = Purchased.Pid');
$query = $this->db->get();