简体   繁体   中英

How to write query similar to this with codeigniter active record?

this is the mysql query i want to write with codeigniter

SELECT r.reciept_no,r.loan_no,r.amount_paid,c.mem_name  
FROM receipts r, customer c 
WHERE r.loan_no = c.loan_no AND reciept_no = '$receipt_id'

any help would be great

Regards

Off the top of my head

$this->db->select('receipts.reciept_no');
$this->db->select('receipts.loan_no');
$this->db->select('receipts.amount_paid');
$this->db->select('receipts.reciept_no');
$this->db->select('customer.mem_name');
$this->db->where('reciept_no', $receipt_id);
$this->db->join('customer', 'receipts.loan_no = customer.loan_no');
$this->db->get('receipts');

The JOIN beeing key here

just a small modification :

$sql = 'r.reciept_no,r.loan_no,r.amount_paid,r.reciept_no,c.mem_name';

$this->db->select($sql)
->where('reciept_no', $receipt_id)
->join('customer as c', 'r.loan_no = c.loan_no')
->get('receipts as r');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM