0

我需要在一个表单中有大约 60 个不同的字段集,它们都包含相同的元素。唯一的区别是我的查询调用的 ID。该 ID 将从 mysql 为我填充数据。

除了添加 60 个字段集之外,还有其他方法可以更有效地做到这一点吗?

<fieldset>
    <h2>Make Your Pick</h2>
        <?php 

        require_once ('mysql_connect.php');

        $query = "SELECT id, name FROM table WHERE id = 1";
        $result = @mysql_query ($query) or die ('error submitting' .mysql_error());

        echo "<select name='winner' id='winner'><option>Who Will Win?</option>";
        while($drop=mysql_fetch_array($result)){

        //data stored in $drop
        echo "<option value=$drop[id]>$drop[name]</option>";
        }
        echo "</select>";

        ?>
    <input id="insert" type="submit" value="Next" />
</fieldset>
4

1 回答 1

0

我找到了答案!

<?php
for ($i = 1; $i <= 60; $i++) {
echo '<fieldset>
<h2 class="fs-title">Make Your Pick</h2>';
        require_once ('mysql_connect.php');

    $query = "SELECT id, name FROM table WHERE id = $i";
    $result = @mysql_query ($query) or die ('error submitting' .mysql_error());

    echo "<select name='winner' id='winner'><option>Who Will Win?</option>";
    while($drop=mysql_fetch_array($result)){

    //data stored in $drop
    echo "<option value=$drop[id]>$drop[name]</option>";
    }
    echo "</select>";

echo '<hr>
<input id="insert" type="button" name="next" class="next action-button" value="Next" />
</fieldset>';
}
?>
于 2013-10-02T19:51:09.453 回答