0

I am trying to select one item form the items table and join the second table (images). The table images will have multiple results for each item. The problem is that the result join is bringing just one result instead of an array with all images data.

The code

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

What I am missing?

Thanks

Bertrand
  • 13,540
  • 5
  • 39
  • 48
  • What's fetchRoll? It looks like fetchAll but it also could be fetchRow.. :) – Liyali Feb 23 '12 at 13:53
  • The result will be always a single item, this array will have another sub array with the data from each image associated to this item (the result of the join). – Bertrand Feb 23 '12 at 14:10

1 Answers1

0

in your post you have $result = $this->fetchRoll($select); i think its a typo error you might be doing $result = $this->fetchRow($select); in your code

but you should use fetchAll instead:

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

see here http://framework.zend.com/manual/en/zend.db.table.html

EDIT : to get the item's data array with a sub array with all images

$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;
Mouna Cheikhna
  • 38,870
  • 10
  • 48
  • 69
  • Thanks for the help MMC Using $this->fetchAll($select) I get an array with the same item repeated many times, so if this item has four images the result array will be four times this item, each item with a different image data. I want the result to be the item's data array with a sub array with all images. Tried to use $select->group('items.item_id') but it brings just one image. – Bertrand Feb 23 '12 at 14:05
  • i added an edit to get the item's data array with a sub array of images – Mouna Cheikhna Feb 23 '12 at 14:21
  • I see your solution MMC, I actually thought that I could bring the result well formated direct from the database, instead of adjusting it with a loop, but this works great and won't consume mucho processing. Thanks a lot MMC!!! – Bertrand Feb 23 '12 at 14:30