Codeigniter/PHP:
This is my current db query:
$pass_check = $this->CI->db->select('code')->from('coupons')->where(array('title'=>'Booyah'))->get();
$pass_check = $pass_check->result_array();
There are two other fields: 'exp_date', and 'start_date'. These represent when the coupon should be available and when it should not.
How can I only select codes/coupons that fall within the applic开发者_开发知识库able date range in the db?
Does that make sense?
The SQL statement to select values between two dates would be something along these lines:
SELECT code
FROM coupons
WHERE title = 'Booyah'
AND CURRENT_DATE BETWEEN start_date and exp_date;
I'm sure you can make the appropriate substitutions for CodeIgniter.
AKA, if the start_date is less than today, don't get it, and if today is after the exp_date don't get it.
But I'm assuming you meant "E.G., if today is less than start_date, don't get it, and if today is greater than exp_date, don't get it."
Here you go: $today = today's date.
$today = date();
$pass_check = $this->CI->db->select('code')->from('coupons')->where(array('title'=>'Booyah'))->$this->db->where("$date BETWEEN start_date and exp_date")->get();
$pass_check = $pass_check->result_array();
精彩评论