这是我的代码:
$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();
我收到了一个错误:
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
我收到了一个错误:
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` = 'elicuarto@apploma.com'
ORDER BY `course_name` ASC
Filename: C:\wamp\www\coursebooking\system\database\DB_driver.php
Line Number: 330
答案 0 :(得分:16)
尝试
$this->db->select('course_name AS `Course Name`, course_desc AS `Course Description`, display_public AS `Display Status`', FALSE);
你的别名中的空间正在弄乱你。
<强>更新强>
我不确定你为什么要这样做,但我没有看到任何阻止你写作的内容
$this->db->select("course_name AS `{$variable}`", FALSE);
(为简单起见只显示一个字段)
更新2
应该是标准的字符串转换,所以我不知道为什么它对你不起作用..总是分裂字符串......
$this->db->select('course_name AS `' . $variable . '`', FALSE);