如何在 CodeIgniter 中使用 OR_Where 和 AND 条件?
How to use OR_Where with AND condition in CodeIgniter?
我正在使用 CodeIgniter。我需要了解 where
和 or_where
条件如何在 codeigniter 查询生成器中工作。
我需要像 where a="" AND b="" AND c="" OR d="" AND e=""
这样的输出
所以我尝试了一个关联数组。
$where= array('a'=>$firstname,'b'=>$lastname,'c'=>1);
$or_where= array('d' =>$customer_mobile,'e'=>1);
但我得到了输出
where a="" AND b="" AND c="" OR d="" OR e=""
你愿意帮忙吗?
是的,我的问题不一样。我询问了 or_where
条件。请检查我的期望输出和获取输出。重复的问题是不同的。
希望对您有所帮助:
像这样使用 query grouping
:根据您的
更改 table name
和 variables
$firstname = 'a';
$lastname = 'b';
$customer_mobile = 'd';
$this->db->select('*')->from('users')
->group_start()
->where('a', $firstname)
->where('b', $lastname)
->where('c', '1')
->or_group_start()
->where('d', $customer_mobile)
->where('e', '1')
->group_end()
->group_end()
->get();
echo $this->db->last_query();
输出将是这样的:
SELECT * FROM `users`
WHERE ( `a` = 'a' AND `b` = 'b' AND `c` = '1'
OR ( `d` = 'd' AND `e` = '1' ) )
更多:https://www.codeigniter.com/user_guide/database/query_builder.html#query-grouping
我正在使用 CodeIgniter。我需要了解 where
和 or_where
条件如何在 codeigniter 查询生成器中工作。
我需要像 where a="" AND b="" AND c="" OR d="" AND e=""
所以我尝试了一个关联数组。
$where= array('a'=>$firstname,'b'=>$lastname,'c'=>1);
$or_where= array('d' =>$customer_mobile,'e'=>1);
但我得到了输出
where a="" AND b="" AND c="" OR d="" OR e=""
你愿意帮忙吗?
是的,我的问题不一样。我询问了 or_where
条件。请检查我的期望输出和获取输出。重复的问题是不同的。
希望对您有所帮助:
像这样使用 query grouping
:根据您的
table name
和 variables
$firstname = 'a';
$lastname = 'b';
$customer_mobile = 'd';
$this->db->select('*')->from('users')
->group_start()
->where('a', $firstname)
->where('b', $lastname)
->where('c', '1')
->or_group_start()
->where('d', $customer_mobile)
->where('e', '1')
->group_end()
->group_end()
->get();
echo $this->db->last_query();
输出将是这样的:
SELECT * FROM `users`
WHERE ( `a` = 'a' AND `b` = 'b' AND `c` = '1'
OR ( `d` = 'd' AND `e` = '1' ) )
更多:https://www.codeigniter.com/user_guide/database/query_builder.html#query-grouping