Nan*_* HE 2 php activerecord codeigniter php-5.3
我有一个关于Active Record Class用法的问题,我的代码片段如下.
$this->db->select('year, distance, gender, rank, name, chiptime, racenumber');
$this->db->order_by("year", "desc");
$this->db->order_by("distance, gender, rank", "asc");
$year = 2010;
$this->db->where('year', $year); // where() doesn't work!
$this->db->like('rank', $keyword); // Assume I didn't add like() with $keywords, where() works well.
$this->db->or_like('name', $keyword);
Run Code Online (Sandbox Code Playgroud)
当我在我的Active Recrod类中$ this-> db-> where()之后绑定$ this-> db-> like()时,$ this-> db-> where()将不会再次工作.它将显示包含$关键字的所有年份记录.
它是在Active Recrod类的限制,或者我没有找到绑定在哪里()和像()一个正确的方式.
感谢您的回复
我认为这是"和"和"或"部分.目前你的WHERE看起来像这样:
WHERE年份= 2010 AND rank = 1 OR name ='Peter'
由于你在那里得到一个OR,它会找到名称为"Peter" 或排名为1且年份为2010的所有内容.
因此,您应该更好地定义您的位置,并在需要时使用圆括号.
| 归档时间: |
|
| 查看次数: |
525 次 |
| 最近记录: |