如何从DB中获取codeigniter中的所有字母? PHP,MySQL,CodeIgniter

时间:2013-11-28 00:31:46

标签: php mysql codeigniter

我用它来获取所有字母来创建字母列表: SELECT DISTINCT SUBSTRING(title, 1, 1) AS letter FROM games ORDER BY letter asc 一切还好。但后来我尝试将它传递给codeigniter,它失败了(试过)了几个变种:​​

$this->db->distinct();
$this->db->select("SUBSTRING(title,1,1) AS letter");
$this->db->order_by("letter", "asc");
$query = $this->db->get('games');

也是这个:

$this->db->query("SELECT DISTINCT SUBSTRING(title,1,1) AS letter ORDER BY letter");
$query = $this->db->get('games');

我一直得到错误号码:1064

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行的“AS letter FROM(games)ORDER BY letter asc”附近使用正确的语法

SELECT DISTINCT SUBSTRING(title, `1`, `1)` AS letter FROM (`games`) ORDER BY `letter` asc

文件名:E:\ wamp \ www \ gamecenter \ system \ database \ DB_driver.php

行号:330

也许有人可以提供帮助? :((

2 个答案:

答案 0 :(得分:1)

将第二个参数传递给select为FALSE

$this->db->select("SUBSTRING(title,1,1) AS letter", FALSE); //This way it will not put the ` characters.

答案 1 :(得分:0)

$ result = $ this-> db-> query('SELECT DISTINCT SUBSTRING(title,1,1)AS letter FROM(games)ORDER BY letter asc') - &gt ;结果();

我认为它会帮助你。