如何在Codeigniter中使用for循环的条件(How to give where condition using for loop in Codeigniter)
我有一个数组:
Array ( [0] => 9055954 [1] => 2736738 [2] => 1234 [3] => 2844725 )我需要一个where条件来选择ids表数据库表add_family的ID不等于任何一个数组中的值,我使用codeigniter,我怎么能检查它使用循环for where条件。
I have an array:
Array ( [0] => 9055954 [1] => 2736738 [2] => 1234 [3] => 2844725 )I need to a where condition to select the ids form database table add_family whose id is not equal to any one of the value in array, I'm using codeigniter, how can I check it using for loop for where condition.
最满意答案
您并不需要运行for循环来执行此操作。 你可以简单地通过运行一个简单的查询来检查它,这个查询将在排除数组后指定的所有记录之后进行检查:
$ignore_ids = [9055954, 2736738, 1234, 2844725]; $this->db->where_not_in('add_family', $ignore_ids);You don't really need to run a for loop to do this. You can simply check it by running a simple query which will select all records from table after excluding ids as specified in array:
$ignore_ids = [9055954, 2736738, 1234, 2844725]; $this->db->where_not_in('add_family', $ignore_ids);更多推荐
发布评论