在PHP CodeIgniter中包含多个要检查的值

2guxujil  于 2022-12-07  发布在  PHP
关注(0)|答案(2)|浏览(130)
public function get_tertiarylevel_present() {
    $checker = array(
        'timestamp' => strtotime(date('Y-m-d')),
        'section_id' => 11,
        'status'    => 1
    );
    $tertiarylevel_present = $this->db->get_where('daily_attendances', $checker);
    return $tertiarylevel_present->num_rows();
}

当前它正在检查'status'值1(仅当前)。如何修改它还检查数据库是否具有'status'值3(延迟)。如果要检查多个值,如何包括在数组中。

ncecgwcz

ncecgwcz1#

您需要使用where_in(https://www.codeigniter.com/userguide3/database/query_builder.html#CI_DB_query_builder::where_in):
这应该可以工作(但尚未测试):

public function get_tertiarylevel_present() {
    $this->db->where('timestamp', strtotime(date('Y-m-d')));
    $this->db->where('section_id', 11);
    $this->db->where_in('status', array(1, 3));
    $tertiarylevel_present = $this->db->get('daily_attendances');
    return $tertiarylevel_present->num_rows();
}
y3bcpkx1

y3bcpkx12#

将Where条件数组更改为:

<pre> <code>

$array = array(  'timestamp' => strtotime(date('Y-m-d')),
    'section_id' => 11, 
    'id >=' => 1
);
</code> </pre>

您应该使用'id〉' =〉1来告诉orm您所指的条件

相关问题