How to use an alias in Codeigniter

Here is my code:

$this->db->select('course_name AS Course Name,course_desc AS Course Description,display_public AS Display Status',FALSE); $this->db->from('courses'); $this->db->where('tennant_id',$tennant_id); $this->db->order_by('course_name','ASC'); $query = $this->db->get(); 

and I got an error message:

 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 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1 SELECT course_name AS Course Name, course_desc AS Course Description, display_public AS Display Status FROM (`courses`) WHERE `tennant_id` = ' avelinocurato@apploma.com ' ORDER BY `course_name` ASC Filename: C:\wamp\www\coursebooking\system\database\DB_driver.php Line Number: 330 
+4
source share
1 answer

Try

 $this->db->select('course_name AS `Course Name`, course_desc AS `Course Description`, display_public AS `Display Status`', FALSE); 

This is the space in your pseudonym that is messing with you.

UPDATE

I'm not sure why you want, but I don’t see anything that prevents you from writing

 $this->db->select("course_name AS `{$variable}`", FALSE); 

(for simplicity, only one field is shown)

UPDATE 2

There should be a standard string conversion, so I don’t know why this does not work for you .. always split the lines ...

 $this->db->select('course_name AS `' . $variable . '`', FALSE); 
+13
source

All Articles