如何每行只有 3 个带有动态复选框编号的复选框

How to have only 3 checkboxes per line with dynamic checkbox number

如何使用动态复选框编号每行只有 3 个复选框,例如我有 21 个复选框(从数据库中读取复选框名称)。

这是我的代码

<div class='form-group'>
    <div class="col-lg-12">
        <?php 
            $sql = "SELECT id, posizione, nome
                    FROM user_livelli";                 
            $result = $conn->query($sql);
            if (!empty($result) && $result->num_rows > 0) {         
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    $id = $row['id'];
                    $posizione = $row['posizione'];
                    $nome = $row['nome'];
                                        
                    echo "<input type='checkbox' name='nome_posiz[]'>" ." " .$nome ." ";
                }
            }
        ?>
    </div>
</div>

我有以下情况

但我希望每行只有 3 个复选框,例如第一行有黑点的 3 个,另一行有红点的 3 个,另一行有绿点的 3 个等等在。像这样使用 PAINT

完成的事情

<div class='form-group'>
    <div class="col-lg-12">
<?php 
    $counter=0;
    $sql = "
    SELECT id
         , posizione
         , nome 
      FROM user_livelli
    ";                 
    $result = $conn->query($sql);
    if (!empty($result) && $result->num_rows > 0) {         
        // output data of each row
        while($row = $result->fetch_assoc()) {
            $counter++;
            $id = $row['id'];
            $posizione = $row['posizione'];
            $nome = $row['nome'];
                                        
            echo "<input type='checkbox' name='nome_posiz[]'>" ." " .$nome ." ";

            if (($counter % 3)==0){
                echo "<br />";//or other formatting you desire,
            }
        }
    }
?>
    </div>
</div>