如何在codeigniter中使用或\u where with和condition?

kzmpq1sx  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(431)

我正在使用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 条件。请检查我的期望输出和获得输出。重复问题是不同的。

u4vypkhs

u4vypkhs1#

希望这能帮助您:
使用 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-分组

相关问题