What i was hoping i would break some functions down and skipping running multiple queries all the time.
Now if i have a ONE-to-MULTI relationship between two tables.
tbl_invoices
and tbl_invoice_items
. Table tbl_invoice_items
has a different row for each item for a specific order.
Would it be possible with a SINGLE query from Codeigniter to get the item from the tbl_invoices
and all the tbl_invoice_items
in an array in the same result ?
Basically JOIN the below queries
$this->db->select('*,tbl_invoices.id AS invoice_id');
$this->db->from('tbl_invoices');
$this->db->where('tbl_invoices.id',$invoice_id);
$data = $this->db->get();
$this->db->select('*');
$this->db->from('tbl_invoice_items');
$this->db->where('tbl_invoice_items.invoice_id',$invoice_id);
$this->db->join('tbl_products','tbl_products.id = tbl_invoice_items.item_id','left');
$data = $this->db->get();
Also would it be able in a ONE-to-ONE relationship tables return the other table as a custom variable ?
Something like:
SELECT tbl_clients.* AS client, tbl_invoices.* FROM...JOIN...WHERE...etc