CodeIgniter Concat
I've spent a few hours staring at this piece of code. Fresh eyes please! Here is a shortened version of the query:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near
'FROM (`requests` c) JOIN `inventory` d ON `d`.`listing_seq_no` = `c' at line 7
SELECT DISTINCT `c`.`req_id`, `u`.`user_id`, `u`.`org_name`,
CONCAT_WS(' ', `l`.`strength`, `l`.`unit)` as dos, `c`.`quantity` AS quantity1,
(SELECT sum(quantity) from inventory d2
WHERE d2.listing_seq_no = c.listing_seq_no
) as inv_total,
FROM (`requests` c)
JOIN `inventory` d
ON `d`.`listing_seq_no` = `c`.`listing_seq_no`
JOIN `listings` l
ON `l`.`listing_seq_no` = `c`.`listing_seq_no`
EDIT: Original CodeIgniter Code snippet:
$this->db->select ( "c.req_id,
u.user_id,开发者_开发问答
u.org_name,
l.tradename as name,
CONCAT_WS(' ', l.strength, l.unit) as dos,
);
This:
CONCAT_WS(' ', `l`.`strength`, `l`.`unit)`
Should be:
CONCAT_WS(' ', `l`.`strength`, `l`.`unit`)
try removing the parens around (requests
c)
It's an old question, but you can use:
$this->db->select("<your_select_portion>", FALSE);
to avoid the auto-quoting feature of the CI DB class. I am a fan of using MySQL functions on select statements with CI, and this usually fixes the problem (except when you start using the query-caching feature, but that's another story).
精彩评论