Codeigniter SQL语句

时间:2012-04-23 06:13:59

标签: php sql codeigniter

我在以下sql语句中遇到了一些问题:

$query= $this->db->get_where('navigation', 'linkname IS NOT NULL 
                             AND parent IS NULL 
                             AND type="main" //this doesn't work!!
                             AND ORDER BY sortnumber ASC');

如何以合理的方式将type =“main”添加到此语句中? 非常感谢!

2 个答案:

答案 0 :(得分:6)

认为错误是您应该只编写ORDER BY,而不是AND ORDER BY

答案 1 :(得分:2)

我建议将'where'子句分成几个语句。它使调试和维护更容易:

$this->db->where('linkname !=', null);
$this->db->where('parent =', null);
$this->db->where('type', 'main');
$this->db->order_by('sortnumber', 'ASC');
$this->db->get('navigation');