Php 如何在codeigniter中从多行获取相同的外键记录

Php 如何在codeigniter中从多行获取相同的外键记录,php,codeigniter,group-by,Php,Codeigniter,Group By,我正在尝试获取数组中具有相同ID的记录。我尝试了“Group_by”查询,但结果是单个数组。请参见下图中的记录 查询: $this->db->select('typeID,projectID,typeName,typeSize,dimensionWidth,dimensionHeight'); $this->db->from('propertytype'); $this->db->group_by('projectID'); $rec=$this->d

我正在尝试获取数组中具有相同ID的记录。我尝试了“Group_by”查询,但结果是单个数组。请参见下图中的记录

查询:

$this->db->select('typeID,projectID,typeName,typeSize,dimensionWidth,dimensionHeight');
$this->db->from('propertytype');
$this->db->group_by('projectID');
$rec=$this->db->get()->result();

echo "<pre>";print_r($rec);exit();
Array(
  [0]=> stdClass object(
      Array(...)
      Array(...)
      Array(...)
      Array(...)
  )

  [1]=> stdClass object(
      Array(...)
      Array(...)
      Array(...)
      Array(...)
  )
)
我想要二维数组的结果,比如

$this->db->select('projectID');
$this->db->from('propertytype');
$this->db->distinct('projectID');
$rec=$this->db->get()->result();
$arr=array();

foreach ($rec as $r) {
    $this->db->select('typeID,projectID,typeName,typeSize,dimensionWidth,dimensionHeight');
    $this->db->from('propertytype');
    $this->db->where('projectID',$r->projectID);
    $rec=$this->db->get()->result();
    $arr[]=$rec;    
}

echo "<pre>";print_r($arr);exit();

告诉我哪里出错了?谁能帮我一下吗。非常感谢。

GROUPBY子句经常与
聚合函数一起使用,以返回每个组的摘要值。不带聚合的
GROUP BY
子句类似于使用
选择DISTINCT
。。。
GROUP BY
子句不排序数据

我希望这能帮助你:

$this->db->select('projectID');
$this->db->from('propertytype');
$this->db->distinct('projectd');
$rec=$this->db->get()->result();
$arr=array();
foreach($rec as$r){
$this->db->select('typeID,projectID,typeName,typeSize,dimensionWidth,dimensionHeight');
$this->db->from('propertytype');
$this->db->where('projectd',$r->projectd);
$rec=$this->db->get()->result();
$arr[]=$rec;
}
回声“;印刷费($arr);退出();

GROUP BY
子句通常与
聚合函数一起使用,以返回每个组的摘要值。不带聚合的
GROUP BY
子句类似于使用
选择DISTINCT
。。。
GROUP BY
子句不排序数据

我希望这能帮助你:

$this->db->select('projectID');
$this->db->from('propertytype');
$this->db->distinct('projectd');
$rec=$this->db->get()->result();
$arr=array();
foreach($rec as$r){
$this->db->select('typeID,projectID,typeName,typeSize,dimensionWidth,dimensionHeight');
$this->db->from('propertytype');
$this->db->where('projectd',$r->projectd);
$rec=$this->db->get()->result();
$arr[]=$rec;
}
回声“;印刷费($arr);退出();

GROUP BY子句通常与聚合函数一起使用,以返回每个组的摘要值。不带聚合的GROUPBY子句类似于使用SELECT DISTINCT。。。GROUP BY子句不会对数据进行排序。您可以使用
order\u BY('projectd')
代替GROUP BY子句通常与聚合函数一起使用,以返回每个组的摘要值。不带聚合的GROUPBY子句类似于使用SELECT DISTINCT。。。GROUP BY子句不对数据进行排序。您可以使用
order\u BY('projectd')
insteadwlc亲爱的Jamal Ahmadwlc亲爱的Jamal Ahmad
$this->db->select('projectID');
$this->db->from('propertytype');
$this->db->distinct('projectID');
$rec=$this->db->get()->result();
$arr=array();

foreach ($rec as $r) {
    $this->db->select('typeID,projectID,typeName,typeSize,dimensionWidth,dimensionHeight');
    $this->db->from('propertytype');
    $this->db->where('projectID',$r->projectID);
    $rec=$this->db->get()->result();
    $arr[]=$rec;    
}

echo "<pre>";print_r($arr);exit();