Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Codeigniter活动记录计数返回null_Mysql_Codeigniter_Count - Fatal编程技术网

Mysql Codeigniter活动记录计数返回null

Mysql Codeigniter活动记录计数返回null,mysql,codeigniter,count,Mysql,Codeigniter,Count,我需要从一个表中选择一些数据,并计算另一个表中的相关图像。 我使用的代码是模型文件中的以下代码 $this->rci_db->select (" $this->tbl_register.id, $this->tbl_register.cor, DATE_FORMAT($this->tbl_register.registerdate, '%d/%m/%Y') AS registerdate, $this

我需要从一个表中选择一些数据,并计算另一个表中的相关图像。 我使用的代码是模型文件中的以下代码

$this->rci_db->select (" 
        $this->tbl_register.id,
        $this->tbl_register.cor,
        DATE_FORMAT($this->tbl_register.registerdate, '%d/%m/%Y') AS registerdate,
        $this->tbl_registrations.registration,
        $this->tbl_aircrafts.cn,
        $this->tbl_aircrafts.built,
        $this->tbl_manufacturers.manufacturer, 
        $this->tbl_models.type AS model,
        COUNT($this->tbl_images.imgid) AS count
        ");
    $this->rci_db->from("$this->tbl_register");
    $this->rci_db->join("$this->tbl_registrations", "$this->tbl_registrations.rid = $this->tbl_register.rid", 'left');
    $this->rci_db->join("$this->tbl_aircrafts", "$this->tbl_register.aid = $this->tbl_aircrafts.aid", 'left');
    $this->rci_db->join("$this->tbl_manufacturers", "$this->tbl_manufacturers.mid = $this->tbl_aircrafts.mid", 'left');
    $this->rci_db->join("$this->tbl_models", "$this->tbl_models.tid = $this->tbl_aircrafts.tid", 'left');
    $this->rci_db->join("$this->tbl_images", "$this->tbl_register.id = $this->tbl_images.id", 'left');

    $this->rci_db->where("$this->tbl_register.rid", $rid);

    $query = $this->rci_db->get();

    if ($query->num_rows() > 0)
    {
        return $query->result();
    }
    return false;
查询为COUNT语句返回null,我无法找出错误所在。 其他数据返回正确
感谢您的帮助。

该计数在另一个表中,因此您必须在查询中以某种方式关联这些计数。在这种情况下,只需使用子选择,而不是加入

在您的选择中类似于以下内容:

$this->rci_db->select (" 
        $this->tbl_register.id,
        $this->tbl_register.cor,
        DATE_FORMAT($this->tbl_register.registerdate, '%d/%m/%Y') AS registerdate,
        $this->tbl_registrations.registration,
        $this->tbl_aircrafts.cn,
        $this->tbl_aircrafts.built,
        $this->tbl_manufacturers.manufacturer, 
        $this->tbl_models.type AS model,
        (SELECT COUNT($this->tbl_images.imgid) FROM $this->tbl_images WHERE $this->tbl_register.id = $this->tbl_images.id) AS count
        ");