2012-04-23 44 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');