2016-05-31 65 views
1

我有一个MySQL查询:转换查询笨

SELECT `percentage` FROM `discount_percentage` WHERE `agent_id`=$agent_id AND `insurance_type_id`=$insurance_type and `entity_id`=$entity_id and `state_id`=$state_id AND CURDATE() between from_date and to_date 

我想改变CURDATE到PHP函数 但日期(Y-M-d)不工作。

以及如何将其更改为纯代码?

+0

你试过NOW的'()''而不是CURDATE()'我知道吗? –

回答

0

更新代码试试下面的代码可以让你得到任何问题

$currentdate=date('Y-m-d'); 
$this->db->select('percentage'); 
$this->db->from('discount_percentage'); 
$this->db->where('agent_id',$agent_id); 
$this->db->where('insurance_type_id',$insurance_type_id); 
$this->db->where('entity_id',$entity_id); 
$this->db->where('state_id',$state_id); 
$this->db->where('from_date >=', $currentdate); 
$this->db->where('to_date <=', $currentdate); 
+0

你确定'在哪里(“$的currentdate> =”' – splash58

+0

不工作:消息:未定义的常量TO_DATE的使用 - 假设“TO_DATE 消息:使用未定义的常量TO_DATE的 - 假设‘?TO_DATE’ 消息:呼叫未定义的方法CI_DB_mysqli_driver :: row_array() – humbleiam

+0

可以请你分享你的表结构 –