2012-04-23 42 views
0

我有一些问题,下面的SQL语句:笨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'); 

我如何添加类型在一个合理的方式进入这一说法=“主”? 非常感谢!

+0

“这不行!!!”是什么意思?它做什么或不做什么? – deceze 2012-04-23 06:17:28

+0

这看起来像STI的工作,但我不确定codeigniter是否完全支持activerecord。 – nurettin 2012-04-23 06:28:06

+0

@deceze感谢评论:“这不起作用”意味着没有这部分“AND type =”main“”该声明有效... – Jurudocs 2012-04-23 06:33:58

回答

6

认为的错误是,你应该只写ORDER BY,不AND ORDER BY

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');