Avoid ordering on request in codeigniter

Here's the SQL query:

SELECT * FROM (`news`) WHERE `country` IS NULL AND `region` IS NULL ORDER BY IFNULL(update_date, `create_date)` DESC

And you may notice that create_date has some formatting error, I would like to disable escape, but even add false after the order_by function, this has no effect. How to fix it? Many thanks

 $this->db->select('*');
 $this->db->from('news');
 $this->db->where($data);
 $this->db->order_by('IFNULL(update_date,create_date)', 'DESC', false);
 $query = $this->db->get();
 return $query->result_array();
+4
source share
3 answers

Use the code below:

$ this-> db → _ protect_identifiers = FALSE;

$ this-> db-> order_by ('IFNULL (update_date, create_date)', 'DESC', false);

$ this-> db → _ protect_identifiers = TRUE;

+7
source

add this line on top of your db select method.

$this->db->_protect_identifiers = FALSE;

+2
source

, SQL CI 3.10

$this->db->order_by("results.result * 1", 'ASC', FALSE);

, FALSE order_by , $this-> db → _ protect_identifiers CI 3.10

0

All Articles