2016-05-31 93 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

可以請你分享你的表結構 –