使用for循环在html表中打印行

时间:2016-03-16 01:56:33

标签: php html

我的表中的行以非特定长度循环,因为可以随时添加或删除单元格中的值。无论如何,这里是代码:

<?php 
    $i = 1;
    foreach($items as $item => $itemValue) { 
    if ($itemValue['item_id'] == $parentItemValue['id']) {
        if (fmod($i,7)) echo '<tr>';
        echo '<td class="inner-td"><input type="checkbox" id="itemId">'.$itemValue['item'].'</td>';
        if (!fmod($i,7)) echo '</tr>';
        $i++;
    }
?>

上面的代码显示了这个: enter image description here

我还尝试了if (!fmod($i,7)) echo '<tr>'if (!fmod($i,8)) echo '</tr>'并给了我这个: enter image description here

另外,if (!fmod($i,10)) echo '<tr>'if (!fmod($i,11)) echo '</tr>'并告诉我: enter image description here

我希望我的桌子看起来像这样: enter image description here

在制作新单元格之前,单元格是否会填充整行?

2 个答案:

答案 0 :(得分:1)

你可以试试这个。只需更改所需列数的12239值即可。

$maxcol

答案 1 :(得分:0)

尝试遵循此结构。 请注意,所有字段和行都由我自己组成。

 <tbody>

        <?php 
        require_once ('connectionWithDB.php');
        $table = "members"; 
        $array = $admin_query->viewTableData($table);
        foreach ($array as $row){
        print_r($array); 
        ?>

        <tr>
         <td> <?php $row[member_id]  ?> </td>
         <td> <?php $row[member_password]  ?> </td>
         <td> <?php $row[member_first_name]  ?> </td>
         <td> <?php $row[member_last_name] ?> </td>
         <td> <?php $row[member_DOB]  ?> </td>
         <td> <?php $row[member_address]  ?> </td>
         <td> <?php $row[member_email]  ?> </td>
         <td> <?php $row[member_phone]  ?> </td>
         <td> <?php $row[member_gender]  ?> </td>
        </tr>
       </tbody>
相关问题