How to get all rows from related table using join

For programming and general questions on Zend Framework
Post Reply
Posts: 1
Joined: Sat Mar 18, 2017 6:09 pm

How to get all rows from related table using join

Post by dani34 » Sat Mar 18, 2017 6:12 pm

I have two tables. First table contain offer details and second table contains offer collection of languages(collection can be selected in main offer form). I want to use query with "join" language table to get all of them in single query. How it's look like: Relation

Trying to get all of the offers I want to get all offer languages as one field.

Code: Select all

     array [
      'id' => string '11',
      'name' => string '134',
      'date' => string '01-12-2016',
      'languages' => array(all language value from related table)
Here is my query:

Code: Select all

        $select = $this->getDbTable()->select()
            ->from(array('o' => 'offers'), array('o.*'))
            ->joinLeft(array('ol' => 'offer_language'), 'ol(.)id_offer = o(.)id', array('ol.*'));

    $resultSet = $this->getDbTable()->fetchAll($select)
In that way if one offer has a three language then I get three same offer with different language field.

Zend Version: 1.11

Thanks for help.
Untitled Diagram.png
Untitled Diagram.png (3.86 KiB) Viewed 1702 times

Post Reply