我有一个关于 Active Record 类使用的问题,下面是我的代码片段。
$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);
当我在 Active Recrod 类中的 $this->db->where() 之后绑定(bind) $this->db->like() 时,$this->db->where() 将不再工作。它将显示包含 $ 关键字的所有年份记录。
是不是Active Recrod Class的限制,还是我没有找到正确的方法来绑定(bind)where()和like()。
感谢您的回复
最佳答案
我认为是“和”和“或”部分。目前你的 WHERE 看起来像这样:
WHERE year = 2010 AND rank = 1 OR name = 'Peter'
因为你在那里有一个 OR,它会找到名称为“Peter”或且排名为 1 且年份为 2010 的所有内容。
所以你应该更好地定义你的位置,并在需要的地方使用圆括号。
关于php - 它是 Active Record 类的 where(), like() 限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7101164/