title: Cakephp 3 Html Table Foreach
body: <p>i would like to ask about HTML a table which involves different models in a Controller view</p>
  <p>inside Users Controller i loaded 3 Models,  Companies, Warehouse, Bank Account</p>
  <p>this User can have multiple companies, and each company has warehouse, bank account</p>
  <p>when i created 1 company, 1 warehouse 1 bank account,  the table is beautiful. (1 foreach each)</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">ID</th>
  <th style="text-align: center;">Name.</th>
  <th style="text-align: center;">Warehouse</th>
  <th style="text-align: center;">Bank Account No</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: center;">Company 1</td>
  <td style="text-align: center;">Warehouse A</td>
  <td style="text-align: center;">1234567</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>when i created 2 companies, 1 warehouse, 1 bank account,  the table is messed up, the warehouse and bank account is looping at the 2nd company which has no data yet</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">ID</th>
  <th style="text-align: center;">Name.</th>
  <th style="text-align: center;">Warehouse</th>
  <th style="text-align: center;">Bank Account No</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: center;">Company 1</td>
  <td style="text-align: center;">Warehouse A</td>
  <td style="text-align: center;">1234567</td>
  </tr>
  <tr>
  <td style="text-align: left;">2</td>
  <td style="text-align: center;">Company 2</td>
  <td style="text-align: center;">Warehouse A</td>
  <td style="text-align: center;">1234567</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>at ID 2,  this is Warehouse and Bank account is looping from the top</p>
  <p>how should i style the HTML for this kind of dynamic table?</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">ID</th>
  <th style="text-align: center;">Name.</th>
  <th style="text-align: center;">Warehouse</th>
  <th style="text-align: center;">Bank Account No</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: center;">Company 1</td>
  <td style="text-align: center;">Warehouse A</td>
  <td style="text-align: center;">1234567</td>
  </tr>
  <tr>
  <td style="text-align: left;">2</td>
  <td style="text-align: center;">Company 2</td>
  <td style="text-align: center;">--</td>
  <td style="text-align: center;">--</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>this is the html Code</p>
  
  <pre><code>&lt;?php foreach ($companies as $company) : ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;?= $this-&gt;Number-&gt;format($company-&gt;id) ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?= h($company-&gt;company_name) ?&gt;&lt;/td&gt;
      &lt;?php endforeach; ?&gt;
  
      &lt;?php foreach ($warehouses as $warehouse) : ?&gt;
          &lt;td&gt;&lt;?= h($warehouse-&gt;warehouse_name) ?&gt;&lt;/td&gt;
  
  
              &lt;?php foreach ($bankAccounts as $bankAccount) : ?&gt;
                  &lt;td&gt;&lt;?= h($bankAccount-&gt;account_name) ?&gt;&lt;/td&gt;
  
                      &lt;?php endforeach; ?&gt;
                  &lt;?php endforeach; ?&gt;
           
      &lt;/tr&gt;
  </code></pre>
  
  <p>Associations of Company Model and Warehouse Model</p>
  <pre><code>    $this-&gt;setTable('companies');
      $this-&gt;setDisplayField('company_name');
      $this-&gt;setPrimaryKey('id');
  
      $this-&gt;belongsTo('Organizations', [
          'foreignKey' =&gt; 'organization_id',
          'joinType' =&gt; 'INNER',
      ]);
      $this-&gt;belongsTo('Positions', [
          'foreignKey' =&gt; 'position_id',
          'joinType' =&gt; 'INNER',
      ]);
      $this-&gt;hasMany('BankAccounts', [
          'foreignKey' =&gt; 'company_id',
      ]);
    
      $this-&gt;hasMany('Warehouses', [
          'foreignKey' =&gt; 'company_id',
      ]);
  
  
  
  
      $this-&gt;setTable('warehouses');
      $this-&gt;setDisplayField('id');
      $this-&gt;setPrimaryKey('id');
  
      $this-&gt;belongsTo('Organizations', [
          'foreignKey' =&gt; 'organization_id',
          'joinType' =&gt; 'INNER',
      ]);
      $this-&gt;belongsTo('Companies', [
          'foreignKey' =&gt; 'company_id',
          'joinType' =&gt; 'INNER',
      ]);
      $this-&gt;belongsTo('Positions', [
          'foreignKey' =&gt; 'position_id',
          'joinType' =&gt; 'INNER',
      ]);
  </code></pre>
  <p>This is the code from the Controllers</p>
  <pre><code>    $companies = $this-&gt;Companies-&gt;find('all')- 
      &gt;where(['Companies.organization_id' =&gt; $organizations['id']]);
  
      $warehouses = $this-&gt;Warehouses-&gt;find('all')- 
      &gt;where(['Warehouses.company_id' =&gt; $organizations['id']]);
  </code></pre>
  <p>thank you very much for Anyone's help and guidance.</p>
  <p>thanks</p>