Could you please tell me how to write database query to search month in date field in Codeigniter's way? Or could you please show me how to write the following query in codeigniter's way?
Thanks in Advance :)
"SELECT attendanceno FROM attendance WHERE (barcodeid = '$studentid') AND (month(attendancedate)='$month' AND year(attendancedate)='$year') ";
Thanks to Stefan, who answered my question below. After reading his post I also tried the following script and found it working. That's why I just wanted to share in case anyone wants to use it. But all credit goes to Stefan. :)
$this->db->select('*');
$this->db->from('attendance');
$this->db->where('barcodeid', $studentid);
$this->db->where('month(attendancedate)', $month);
$this->db->where('year(attendancedate) ', $year);
$this->db->order_by('attendancedate ','ASC');
$getData = $this->db->get('', $perPage, $uri);
If date and month are strings:
$this->db->query("SELECT attendanceno FROM attendance WHERE (barcodeid = ?) AND (month(attendancedate)=? AND year(attendancedate)=?)", array($studentid, $month,$year));
if they are integers
$this->db->query("SELECT attendanceno FROM attendance WHERE (barcodeid = ?) AND (MONTH(attendancedate)='?' AND YEAR(attendancedate)='?')", array($studentid, $month,$year));