开发者

Is it a Active Record Class where(), like() limitation?

开发者 https://www.devze.com 2023-03-29 01:26 出处:网络
I got a question on Active Record Class usage, my code snippet below. $this->db->select(\'year, distance, gender, rank, name, chiptime, racenumber\');

I got a question on Active Record Class usage, my code snippet below.

$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', $keywo开发者_运维技巧rd); // Assume I didn't add like() with $keywords, where() works well.
$this->db->or_like('name', $keyword); 

When I bind $this->db->like() after $this->db->where() in my Active Recrod Class, the $this->db->where() wont’ work again. It will show all the years record that including the $keyword.

Is it a limitation in Active Recrod Class, or I didn’t find a right way to bind where() and like().

Appreciated for your replies


I think it's the "and" and "or" part. Currently your WHERE looks like this:

WHERE year = 2010 AND rank = 1 OR name = 'Peter'

Since you got an OR there, it will find everything with the name "Peter" or with rank is 1 and year is 2010.

So you should define your where better and use round brackets where needed.


Have you tried to use codeigniter active record method chaining?; like:

$this->db->where(...)->like(...);
0

精彩评论

暂无评论...
验证码 换一张
取 消