【发布时间】:2011-08-18 00:45:41
【问题描述】:
我有一个关于 Active Record 类使用的问题,下面是我的代码 sn-p。
$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() 之后绑定 $this->db->like() 时,$this->db->where() 将无法再次工作。它将显示包括$关键字在内的所有年份记录。
是 Active Recrod 类的限制,还是我没有找到正确的方法来绑定 where() 和 like()。
感谢您的回复
【问题讨论】:
-
您是否尝试过 codeigniter 活动记录是否允许链接(我怀疑但尝试),例如:
$this->db->where(...)->like(...);? -
我还没试过。我想尝试一下并稍后更新。谢谢。
-
@hakre,我试过
$year = 2010; $this->db->where('year', $year)->like('name', $keyword)->or_like('chiptime', $keyword)->or_like('racenumber', $keyword); // chaining style。有用!您的评论正是正确的答案。谢谢。 ` -
很高兴听到它对您有用,我将其添加为答案。
标签: php codeigniter activerecord php-5.3