i am working in codeigniter project when i try to get datas from database using 5 tables in a single query.
In phpmyadmin sql query works fine but codeigniter query not working.
My Phpmyadmin Query :
select sma_sales.date, sma_sales.reference_no, biller, sma_companies.name as DeliveryRep,customer,c.code,
GROUP_CONCAT(CONCAT(sma_sale_items.product_name, ' (', sma_sale_items.quantity, ')') SEPARATOR '
') as iname,
grand_total, paid, sma_payments.amount as pyname,
payment_status
from sma_sales
left outer join sma_sale_items on sma_sale_items.sale_id=sma_sales.id
left outer join sma_companies on sma_companies.id=sma_sales.delivered_id
left outer join sma_companies as c on c.id=sma_sales.customer_id
left outer join sma_warehouses on sma_warehouses.id=sma_sales.warehouse_id
left outer join sma_payments on sma_payments.sale_id=sma_sales.id
group by sma_sales.id
My Codeigniter query:
->select("date, reference_no, biller, companies.name as DeliveryRep,customer,c.code, "
. "GROUP_CONCAT(CONCAT(" . $this->db->dbprefix('sale_items') . ".product_name,"
. " ' (', " . $this->db->dbprefix('sale_items') . ".quantity, ')') SEPARATOR '
') as iname,"
. " grand_total, paid,payments.amount as pyname, payment_status", FALSE)
->from('sales')
->join('sale_items', 'sale_items.sale_id=sales.id', 'left')
->join('companies', 'companies.id=sales.delivered_id', 'left')
->join('companies as c', 'c.id=sales.customer_id', 'left')
->join('warehouses', 'warehouses.id=sales.warehouse_id', 'left')
->join('payments', 'payments.sale_id=sales.id', 'left')
->group_by('sales.id')
$q = $this->db->get();
sma nothing but database prefix