Issue
I have to query something that has a where condition with >=
and =<
but I have no luck. This is in CODEIGNITER.
This is the natural way in mysql query:
SELECT COUNT(payment.keyid) AS rec_count, `product_key`.`client_name`,
`product_key`.`contact_email`, `product_key`.`status`, `product_key`.`id`,
`payment`.`paymentdate`, (payment.id) as pid, `payment`.`subscription_type`
FROM (`product_key`)
LEFT OUTER JOIN `payment` ON `payment`.`keyid`=`product_key`.`id`
WHERE `payment`.`paymentdate` >= '2013-08-01'
AND `payment`.`paymentdate` =< '2013-08-31'
AND `status` = 'purchased'
GROUP BY `product_key`.`id`
ORDER BY `client_name` asc
And this is what I have:
return $this->db
->select('COUNT(payment.keyid) AS rec_count')
->select('product_key.client_name, product_key.contact_email, product_key.status, product_key.id, payment.paymentdate, (payment.id) as pid,payment.subscription_type')
->from('product_key')
->where('payment.paymentdate >=', $month_start)
->where('payment.paymentdate =<', $month_end)
->where('status', 'purchased')
->join('payment', 'payment.keyid=product_key.id', 'left outer')
->order_by('client_name', "asc")
->group_by('product_key.id')
->get()
->result();
Maybe someone could help me on this. Thanks.
Solution
Change =<
to <=
.
I also tested your current query in phpmyadmin, because i could not believe that it does not throw an error. But mine does it. So your query should not work in phpmyadmin.
#1064 - 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 '=< ...' at line ...
Answered By - Tobias Golbs
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.