php - Codeigniter order by time - query generation -
i need mysql query like
select *, concat(pri_hours, ':', pri_minutes, ' ', if(pri_ampm = 1, 'am', 'pm')) hr (`sms_primary`) order str_to_date(hr, '%h:%i %p')
and use codeigniter wrote query below
$this->db->select("*,concat(pri_hours,':', pri_minutes,' ',if(pri_ampm = 1,'am','pm')) hr",false); $this->db->from('sms_primary'); $this->db->order_by("str_to_date(hr,'%h:%i %p')");
but not getting expected query below
select *, concat(pri_hours, ':', pri_minutes, ' ', if(pri_ampm = 1, 'am', 'pm')) hr (`sms_primary`) order str_to_date(hr, `'%h:%i` %p')
i hope spot out difference in generated query. injection off unwanted operator `. want remove it.how that?
change
str_to_date(hr, `'%h:%i` %p')
to
str_to_date(hr, '%h:%i %p')
codeigniter adding backticks. use before query
$this->db->_protect_identifiers=false;
hope helps
Comments
Post a Comment