【问题标题】:Convert query between date to codeigniter将日期之间的查询转换为 codeigniter
【发布时间】:2016-09-29 02:44:37
【问题描述】:

我有一个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 TO php 函数 但是 date(Y-m-d) 不起作用。

以及如何将其更改为纯 codeigniter?

【问题讨论】:

  • 你试过NOW()而不是CURDATE()吗?

标签: php mysql codeigniter date


【解决方案1】:

更新代码如果您遇到任何问题,请尝试下面的代码让我知道

$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);

【讨论】:

  • 你确定where('$currentdate &gt;=' 吗?
  • 不工作:消息:使用未定义的常量 to_date - 假定为 'to_date 消息:使用未定义的常量 to_date - 假定为 'to_date' 消息:调用未定义的方法 CI_DB_mysqli_driver::row_array()
  • 你能分享一下你的表结构吗
  • 表结构:如果不存在则创建表discount_percentage (id int(11) NOT NULL, agent_id int(11) NOT NULL, insurance_type_id int(11) NOT NULL, entity_id int(11) NOT NULL, state_id int(11) DEFAULT NULL, percentage float NOT NULL, from_date date NOT NULL, to_date date NOT NULL) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=拉丁语1;
  • @humbleiam 检查我更新的代码,如果您有任何问题,请告诉我
猜你喜欢
  • 2022-01-10
  • 2011-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多