左表中有多个结果的Zend联接



我正试图从项目表中选择一个项目,并加入第二个表(图像)。表格图像将为每个项目提供多个结果。问题是,结果联接只带来一个结果,而不是一个包含所有图像数据的数组。

代码

    $select = $this->select();
    $select->setIntegrityCheck(false);
    $select->from($this)
           ->joinLeft('items_images', 'items.item_id = image_item_id')
           ->where($where);
    $result =  $this->fetchRoll($select);

我缺少什么?

感谢

在您的帖子中,您有$result = $this->fetchRoll($select);我想你可能是打字错误代码中的$result = $this->fetchRow($select);

但是您应该使用fetchAll:

$result =  $this->fetchAll($select);

看这里http://framework.zend.com/manual/en/zend.db.table.html

编辑:获取带有所有图像的子数组的项目数据数组

$results =  $this->fetchAll($select);
$item['item_id'] = $result[0]['item_id'];
//put other item's data here in item
$images = array();
$i = 0;
foreach($results as $result){
  $images[$i]['image_id'] = $result['image_id']
  $images[$i]['image_name'] = $result['image_name']
  //put other image's data here in $images[$i]
  $i++;
}
$item['images'] = $images;

最新更新