首页 > 解决方案 > 使用数据库中的多行自动递增循环

问题描述

我有一个 mysql 查询,它从数据库中提取一个变量并根据变量的数量重复一些 html。然后它根据自动增量为单选按钮分配一个 ID。

当查询只返回一行时,这工作正常,但是当返回 2 行时,它会将 ID 0 分配给 2 批单选按钮,然后分配 1、2、3 等

<?php
$roster_infantry_raw = tep_db_query("select * from " . $table . " where name = '" . $_GET['model'] . "'");
while ($infantry = tep_db_fetch_array($roster_infantry_raw)) {
    for ($i = 0; $i < (int) $infantry['count_min']; $i++) {
?>
        <table class="table table-striped table-hover">
            <tr>
                <td scope="row">
        <?php echo tep_draw_radio_field('weapon1[' . $i . ']', 'weapon1', true); ?></td>
            </tr>
        </table>
    <?php
    }
}?>

标签: phphtmlmysqlauto-increment

解决方案


推荐阅读