“大于或等于”和“小于或等于”CODEIGNITER

时间:2022-09-18 12:55:58

I have to query something that has a where condition with ">=" and "=<" but I have no luck. This is in CODEIGNITER.

我必须使用“> =”和“= <”来查询具有where条件的内容,但我没有运气。这是在CODEIGNITER中。

This is the natural way in mysql query:

这是mysql查询中的自然方式:

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.

也许有人可以帮我这个。谢谢。

4 个解决方案

#1


9  

Change =< to <=.

改变= <到<=。< p>

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.

我还在phpmyadmin中测试了你当前的查询,因为我无法相信它不会抛出错误。但我的确如此。所以你的查询不应该在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 ...

#2


6  

Try to change the =< to <= like

尝试将= <更改为<= like< p>

->where('payment.paymentdate >=', $month_start)
->where('payment.paymentdate <=', $month_end)

And better but not cumpolsury to join the table before the where condition.Now your query should be like

而且更好但不是cumpolsury在where条件之前加入表。现在你的查询应该是这样的

->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')         
->join('payment', 'payment.keyid=product_key.id', 'left outer')    
->where('payment.paymentdate >=', $month_start)
->where('payment.paymentdate <=', $month_end)
->where('status', 'purchased')
->order_by('client_name', "asc")
->group_by('product_key.id')
->get()

#3


0  

Try:

尝试:

$this->db
->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', false)
->from('product_key')
->join('payment', 'payment.keyid=product_key.id', 'LEFT OUTER')
->where('payment.paymentdate >=', '2013-08-01')
->where('payment.paymentdate =<', '2013-08-31')
->where('status', 'purchased')
->group_by('product_key.id')
->order_by('client_name', 'asc')
->get();

#4


0  

from what i know, you can write them like this

据我所知,你可以这样写

$this->db->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', false);
$this->db->where('payment.paymentdate >= "2013-08-01"');
$this->db->where('payment.paymentdate <= "2013-08-31"');
$this->db->where('status', 'purchased');
$this->db->group_by('product_key.id');
$this->db->order_by('client_name', 'asc');
$this->db->join('payment', 'payment.keyid=product_key.id', 'LEFT OUTER')
$this->db->get('product_key');

#1


9  

Change =< to <=.

改变= <到<=。< p>

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.

我还在phpmyadmin中测试了你当前的查询,因为我无法相信它不会抛出错误。但我的确如此。所以你的查询不应该在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 ...

#2


6  

Try to change the =< to <= like

尝试将= <更改为<= like< p>

->where('payment.paymentdate >=', $month_start)
->where('payment.paymentdate <=', $month_end)

And better but not cumpolsury to join the table before the where condition.Now your query should be like

而且更好但不是cumpolsury在where条件之前加入表。现在你的查询应该是这样的

->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')         
->join('payment', 'payment.keyid=product_key.id', 'left outer')    
->where('payment.paymentdate >=', $month_start)
->where('payment.paymentdate <=', $month_end)
->where('status', 'purchased')
->order_by('client_name', "asc")
->group_by('product_key.id')
->get()

#3


0  

Try:

尝试:

$this->db
->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', false)
->from('product_key')
->join('payment', 'payment.keyid=product_key.id', 'LEFT OUTER')
->where('payment.paymentdate >=', '2013-08-01')
->where('payment.paymentdate =<', '2013-08-31')
->where('status', 'purchased')
->group_by('product_key.id')
->order_by('client_name', 'asc')
->get();

#4


0  

from what i know, you can write them like this

据我所知,你可以这样写

$this->db->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', false);
$this->db->where('payment.paymentdate >= "2013-08-01"');
$this->db->where('payment.paymentdate <= "2013-08-31"');
$this->db->where('status', 'purchased');
$this->db->group_by('product_key.id');
$this->db->order_by('client_name', 'asc');
$this->db->join('payment', 'payment.keyid=product_key.id', 'LEFT OUTER')
$this->db->get('product_key');