0

我遇到了以下 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" 添加到此语句中?非常感谢!

4

2 回答 2

6

认为错误在于你应该只写ORDER BY,而不是AND ORDER BY.

于 2012-04-23T06:17:26.047 回答
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');
于 2012-04-23T06:26:53.657 回答