php - Codeigniter db select where 作为数组

标签 php mysql codeigniter

我需要使用这段代码从数据库获取结果,我正在使用 codeigniter。这就是查询的样子,

        $this->db->select('*');
        $this->db->where('broadcast_id', $bid);
        $query = $this->db->get('ih_noticeboard');
        $result = $query->result();
        if($query->num_rows() < 1){
            $data = "no feed ";
        }else{
            $data = $result;
        }

where子句中的$bid就是从这段代码中获取的,

    $this->db->select('broadcast_id');
    $this->db->where('broadcast_subscribers', $id);
    $query = $this->db->get('ih_broadcastors    ');
    if($query->num_rows() < 1){
        $data = "user not subscribed to any broadcasting";
    }else{
        $ress = $query->result();
        foreach ($ress as $row){
            $bid = $row->broadcast_id;
        }`

现在 select 只使用了一个 $bid,如何将 $bid 用作数组?

最佳答案

这很简单。 只需使用 $this->db->where_in('broadcast_id', $bid);

相反,如果 $this->db->where('broadcast_id', $bid);

https://ellislab.com/codeigniter/user-guide/database/active_record.html#select

关于php - Codeigniter db select where 作为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28499080/

相关文章:

php - MySQL根据SELECT查询结果插入多行

mysql - 从具有 20 000 000 行的表中选择计数

codeigniter - 将 CMS 子系统添加到 Codeigniter 站点

php/mysql 事务在失败时不回滚(Codeigniter 框架)

php - 在新标签页中从 FPDF 打开 PDF

php - ReflectionClass 转换为 "normal"Class

PHP Docblock #@+ 含义

php - 如何通过在浏览器中运行页面来删除文件和文件夹?

php - 在 ul 中输出每个数组

php - 如何使用zf2向mysql插入数据?