【问题标题】:Unknown array in where clausewhere 子句中的未知数组
【发布时间】:2014-04-09 14:03:33
【问题描述】:

我在 where 子句中得到错误未知数组。我知道 $project 是一个数组,但是如何在 where 子句中解决这个问题?(我正在使用 codeigniter)。

<?php

function rapport_detail_opbrengsten($idKlant) {
    $this->db->from('Project');
    $this->db->join('Opbrengsten', 'Opbrengsten.idProject = Project.idProject');
    if ($idKlant > 0) {
        $this->db->where('idKlant', $idKlant);
    }
    $query = $this->db->get();
    $project = array();
    foreach ($query->result() as $row) {
        $project[] = $row->idProject;
    }
    $test[] = $project;

    $this->db->select('idProject, SUM(Prijs) as total');
    $this->db->from('Opbrengsten');
    $this->db->where_in('idProject', $test);
    $this->db->group_by('idProject');
    $query = $this->db->get();

    if ($query->num_rows() > 0) {
        return $query->result();
    } else {
        return false;
    }
}

?>

【问题讨论】:

  • 您在哪一行出现错误?
  • 与 where_in('idProject',$test); 的那一行
  • 你能在上面写print_r($test)吗?
  • 数组 ( [0] => 数组 ( [0] => 7 [1] => 14 [2] => 14 [3] => 81 [4] => 81 [5] => 81 [6] => 14 [7] => 9 [8] => 15 [9] => 11 [10] => 12 [11] => 6 [12] => 6 [13] => 6 [14] => 6 ) )
  • 我知道它是一个数组,但我想将所有数组值用于 where in 变量。

标签: php sql arrays codeigniter


【解决方案1】:

应该是$test[0] 而不是$test

【讨论】:

    猜你喜欢
    • 2011-12-05
    • 2011-06-03
    • 1970-01-01
    • 2021-09-19
    • 2020-06-28
    • 2021-07-02
    • 2019-08-14
    • 2013-07-18
    相关资源
    最近更新 更多