sql - Zend2 combine tablegateway array -


i'm new zend2, , want combine 2 tablegateway objects

i have 2 tables: prices , sizes. every price has multiple sizes. want join these tables array, can list prices sizes in it.

for example:

array(         1 => array(                 'price' => 45,                 'description' => 'lorem ipsum',                 'sizes' => array(                     1 => '16',                     2 => '17',                     3 => '20',                     4 => '21'                 )         ),         2 => array(                 'price' => 50,                 'description' => 'lorem ipsum',                 'sizes' => array(                     1 => '34',                     2 => '12',                     3 => '21',                     4 => '50'                 )         )     ) 

my pricestable.php:

public function getpricesbyjewel($jewel) {     $rowset = $this->tablegateway->select(array('jewelid' => $jewel));     return $rowset; } 

my sizestable.php

public function getsizesbyprice($price) {     $rowset = $this->tablegateway->select(array('priceid' => $price));     return $rowset; } 

how list prices (so without sizes in it)

$jewelprices = array('jewelryprices' => $this->getpricestable()->getpricesbyjewel($jewel->id)); $jewelsizes = array('jewelrysizes' => $this->getsizestable()->getsizesbyprice($priceid); 

how list sizes prices array of tables in controller?

fixed inner join:

pricetable.php

public function getpricesbyjewel($jewel) {     $sql = new sql($this->tablegateway->getadapter());      $select = $sql->select();     $select->from('jewelry_prices')         ->join('jewelry_sizes', 'jewelry_prices.id=jewelry_sizes.priceid')         ->where('jewelry_prices.jewelid='.$jewel);     $resultset = $this->tablegateway->selectwith($select);     return $resultset; } 

controller:

$prices = array('jewelryprices' => array()); foreach($this->getpricestable()->getpricesbyjewel($jewel->id) $key => $price){             if(!array_key_exists($price->priceid, $prices['jewelryprices'])){                 $prices['jewelryprices'][$price->priceid] = array(                     'ordernote' => $price->ordernote,                     'price'     => $price->price,                     'description' => $price->description,                     'sizes'     => array()                 );                 array_push($prices['jewelryprices'][$price->priceid]['sizes'], $price->size);             } else {                 array_push($prices['jewelryprices'][$price->priceid]['sizes'], $price->size);             }         } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -