Riandy Riandy - 24 days ago 6
MySQL Question

Make Query in Codeigniter

I have some queries here with native procesdure can anyone help me to convert it to CODEIgniter style that saved in MODEL Folder.

Here my Query :



SELECT
CONCAT(address.firstname,' ',
address.lastname) AS `Name`,
address.email AS Email,
items.created_at AS Date,
items.`name` AS Description,
items.store_id AS Logon,
items.`name` AS Category,
items.store_id AS FeedbackDate,
items.sku AS ProductSearchcode,
items.order_id AS Orderref,
orders.grand_total
FROM sales_flat_order AS orders
JOIN sales_flat_order_item AS items
ON items.order_id = orders.entity_id
LEFT JOIN sales_flat_order_address AS address
ON orders.entity_id = address.parent_id
WHERE
items .created_at BETWEEN '2016-07-01' AND '2016-07-31'
AND orders.status = 'complete'





I hope anyone can help me :)
Regards

Answer

All answer is correct, but batter is used with Query Builder Class like bellow :

$this->db->select("CONCAT(address.firstname,' ',address.lastname) AS `Name`,
address.email AS Email, items.created_at AS Date, items.`name` AS Description,
items.store_id AS Logon, items.`name` AS Category, items.store_id AS FeedbackDate,
items.sku AS ProductSearchcode, items.order_id AS Orderref, orders.grand_total");

$this->db->from("sales_flat_order AS orders");
$this->db->join("sales_flat_order_item AS items", "items.order_id = orders.entity_id");
$this->db->join("sales_flat_order_address AS address", "orders.entity_id = address.parent_id", "LEFT");
$this->db->where("items.created_at BETWEEN  '2016-07-01' AND '2016-07-31'");
$this->db->where("orders.status", "complete");

$query = $this->db->get();
$result = $query->result_array();