在php的基于表的数组中管理列和行


Manage column and row on a table based array of php

我使用dompdf创建我的pdf文档。我的情况是,我必须在数据库上创建一个基于两个查询的表。

这两个查询的返回是数组both。

第一个阵列具有28个ELEMENT,第二个阵列具有27个元素。我想像这个一样解释它们

---------------------------------------------------------
|      FIRST ARRAY          |      SECOND ARRAY         |
---------------------------------------------------------
|  1  |  8   |  15  |  22   |  1  |  8   |  15  |  22   |
|  2  |  9   |  16  |  23   |  2  |  9   |  16  |  23   |
|  3  |  10  |  17  |  24   |  3  |  10  |  17  |  24   |
|  4  |  11  |  18  |  25   |  4  |  11  |  18  |  25   |
|  5  |  12  |  19  |  26   |  5  |  12  |  19  |  26   |
|  6  |  13  |  20  |  27   |  6  |  13  |  20  |  27   |
|  7  |  14  |  21  |  28   |  7  |  14  |  21  |       |
---------------------------------------------------------

但现在,用我的html和php代码:

<tr>
    <td colspan="4" align="center">FIRST ARRAY</td>
    <td colspan="4" align="center">SECOND ARRAY</td>
</tr>
<?php 
    $i = 0;
    foreach ($damage_codes as $row) : ?>
        <?= ($i % 4 == 0) ? "<tr>" : false; ?>
        <?= "<td>[".$row->DAMAGE_ID . "]" . $row->NAMA_DAMAGE . "</td>"; ?>
    <?php 
    $i++;
    endforeach;
    echo "</tr>"
?>
<?php 
    $i = 0;
    foreach ($repair_codes as $row) : ?>
        <?= ($i % 4 == 0) ? "<tr>" : false; ?>
        <?= "<td>[".$row->REPAIR_ID . "]" . $row->NAMA_REPAIR . "</td>"; ?>
    <?php 
    $i++;
    endforeach;
    echo "</tr>"
?>
<tr>

给我这样的结果:

    ---------------------------------------------------------
|      FIRST ARRAY          |      SECOND ARRAY         |
---------------------------------------------------------
|  1  |  2   |  3   |  4    |  
|  5  |  6   |  7   |  8    |  
|  9  |  10  |  11  |  12   |  
|  13 |  14  |  15  |  16   |  
|  17 |  18  |  19  |  20   |  
|  21 |  22  |  23  |  24   |  
|  25 |  26  |  27  |  28   |  

---------------------------------------------------------

如何像我希望的那样得到他们,任何帮助都非常感激。谢谢

已更新,我的表的结果中有一些错误的类型。所以,我更新了我的问题。很抱歉。

在td列上创建两个表

<tr>
    <td colspan="4" align="center">FIRST ARRAY</td>
    <td colspan="4" align="center">SECOND ARRAY</td>
</tr>
<tr>
    <td colspan="4" align="center">
         <table>
             <tr>
              <?php 
    $i = 0;
    foreach ($damage_codes as $row) : ?>
        <?= ($i % 4 == 0) ? "</tr><tr>" : ""; ?>
        <?= "<td>[".$row->DAMAGE_ID . "]" . $row->NAMA_DAMAGE . "</td>"; ?>
    <?php 
    $i++;
    endforeach;
?>
             </tr>
         </table>
    </td>
    <td colspan="4" align="center">
         <table>
             <tr>
              <?php 
    $i = 0;
    foreach ($repair_codes as $row) : ?>
        <?= ($i % 4 == 0) ? "</tr><tr>" : ""; ?>
        <?= "<td>[".$row->REPAIR_ID . "]" . $row->NAMA_REPAIR . "</td>"; ?>
    <?php 
    $i++;
    endforeach;
?>
             </tr>
         </table>
    </td>
</tr>