我在电子商务平台上工作。我有正常形式的查询。我想转换为codeigniter。
这是我的查询
SELECT products.product_name,products.product_id,products.short_description,pi.img,
CASE WHEN products.sp_price=0 THEN products.price WHEN products.sp_price!=0 THEN products.sp_price END as pprice FROM
(`offers_products`) JOIN `products` ON `offers_products`.`product_id` = `products`.`product_id`
LEFT JOIN (SELECT image_name as img,product_id as pid from product_images GROUP BY pid)pi
ON `products`.`product_id` = `pi`.`pid` .
如何将此转换为codeigniter查询。
我试过了,但是语法错误了。请帮助我,我是codeigniter的新手。
答案 0 :(得分:1)
无需转换您的查询。而且你也不应该只使用codeigniter查询。
你可以使用
$res = $this->db->query("your query here")->result();
$res
将拥有您想要的result()
。
这对你有帮助。
有关详情,请查看here
答案 1 :(得分:0)
只需使用
public function method_name()
{
$query = $this->db->query("SELECT products.product_name,products.product_id,products.short_description,pi.img, CASE WHEN products.sp_price=0 THEN products.price WHEN products.sp_price!=0 THEN products.sp_price END as pprice FROM (`offers_products`) JOIN `products` ON `offers_products`.`product_id` = `products`.`product_id` LEFT JOIN (SELECT image_name as img,product_id as pid from product_images GROUP BY pid)pi ON `products`.`product_id` = `pi`.`pid`");
$result = $query->result_array();
return $result;
}
我们将result_array
用于传递数据作为目标数组