How can I get values between two dates in Codeigniter query function? Here is my model and sample code.
function get_promo() {
$today = date('Y-m-d');
$query = $this->db->query('SELECT FROM tbl_event WHERE event_id = $id AND event_startdate <= $today
AND event_enddate >= $today');
return $query;
}
But it doesn't work, here is the error I got
A Database Error Occurred
Error Number: 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 'FROM tbl_event WHERE event_id = 36 AND event_startdate <= 2011-06-09 ' at line 1
SELECT FROM tbl_event WHERE event_id = 36 AND event_startdate <= 2011-06-09 AND event_enddate >= 2011-06-09
Filename: C:\xampp\htdocs\hotel\system\database\DB_driver.php
Line Number: 330
*betweenSELECTandFROM. This explains the error in your question. The next problem that you'll have is about quoting your values. You should not be injecting PHP variables into your SQL string this way -- it is insecure/unstable.