首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多表Codeigniter中的内连接

问多表Codeigniter中的内连接
EN

Stack Overflow用户
提问于 2019-03-28 12:20:21
回答 3查看 32关注 0票数 0

我想在codeigniter的crudodel中创建一个显示函数来显示13号发票上的记录。我将在sql上运行以下查询。它按照我的要求工作。现在,我必须使用内连接将这个查询转换为codeigniter。

代码语言:javascript
复制
SELECT b1.Invoice_No,
       cust_name,
       cust_address,
       cust_contact,
       Item_name,
       Item_qty,
       Item_amount
FROM tbl_bill_invoice AS b1
INNER JOIN tbl_billmenu AS b2 ON(b2.Invoice_No = b1.Invoice_No)
INNER JOIN tbl_billcustomer AS b3 ON(b3.cust_id = b1.cust_id)
WHERE b1.Invoice_no = 13
EN

回答 3

Stack Overflow用户

发布于 2019-03-28 12:30:25

尝尝这个

代码语言:javascript
复制
$this->db->select('b1.Invoice_No, cust_name, cust_address, cust_contact, Item_name, Item_qty, Item_amount');
$this->db->from(' tbl_bill_invoice as b1');
$this->db->join('tbl_billmenu as b2', 'b2.Invoice_No = b1.Invoice_No', 'inner');
$this->db->join('tbl_billcustomer as b3', 'b3.cust_id = b1.cust_id', 'inner');
$this->db->where('b1.Invoice_no', 13);
return $this->db->get()->row();
票数 0
EN

Stack Overflow用户

发布于 2019-03-28 12:35:13

你看,

代码语言:javascript
复制
$invoice_no = 13;
$this->db->select('b1.Invoice_No, cust_name, cust_address, cust_contact, Item_name, Item_qty, Item_amount');
$this->db->from('tbl_bill_invoice b1');
$this->db->join('tbl_billmenu b2', 'b2.Invoice_No = b1.Invoice_No', 'inner');
$this->db->join('tbl_billcustomer b3', 'b3.cust_id = b1.cust_id', 'inner');
$this->db->where('b1.Invoice_no', $invoice_no);
$query = $this->db->get();
if ($query->num_rows() > 0) {
    return $query->row();
} else {
    return array();
}
票数 0
EN

Stack Overflow用户

发布于 2019-03-28 15:31:05

只需编写以下代码

代码语言:javascript
复制
$sql = "SELECT b1.Invoice_No,
   cust_name,
   cust_address,
   cust_contact,
   Item_name,
   Item_qty,
   Item_amount
   FROM tbl_bill_invoice AS b1
   INNER JOIN tbl_billmenu AS b2 ON(b2.Invoice_No = b1.Invoice_No)
   INNER JOIN tbl_billcustomer AS b3 ON(b3.cust_id = b1.cust_id)
   WHERE b1.Invoice_no = 13";
$result = $this->db->query($sql)->result();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55390114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档