doujiexin1136 2019-03-27 21:30
浏览 59
已采纳

使用PHP从数据库发出填充选择框

Basically, I have 1 selection box at the top of my page, called cups. There are 8 teams assigned to each cup. Upon selecting a cup and hitting submit I want all of the teams associated in that cup to fill 8 selection boxes elsewhere on the page allowing the user to choose which team plays the other.

I've attempted many things, and I have got to the point where I can echo the teams, they simply aren't being echoed into the selection boxes in a different div on the same page

<input type="submit" name="submit" value="Generate" class="submit">
<?php
if (isset($_POST['submit'])) { //checking if submit button was clicked

    include_once 'action/dbcon.php';

    $cname = $_POST['cupname'];

    if (empty($cname)) {
        header("Location: ../table.php?field=empty"); //return them if fields are empty
        exit();
    } else {
        $sql = "SELECT * FROM teams WHERE cup_name='$cname'";
        $show_teams = mysqli_query($conn, $sql);

        if (!$show_teams) {
            echo "Could not load teams! " . "(" . mysqli_error($conn) . ")";
        }
        while ($team = mysqli_fetch_assoc($show_teams)) {
            echo $team["team_name"];
        }
    }
    echo "dank";
}
?>
</form>


    <div class="seed-container">
        <div class="column-1">
        <form class="seed-form">
            <select name="team" required>
            <option></option>
            </select>
            <select name="team" required>
            <option></option>
            </select>

So, I'm echoing the right results, just not as options in the selection boxes where I want them

  • 写回答

2条回答 默认 最新

  • dsp1836 2019-03-27 21:40
    关注

    most easy might be to echo them where they should appear:

    <select name="team" required>
    <?php while ($team = mysqli_fetch_assoc($show_teams)) { ?>
        <option value="<?php echo $team["team_id"]; ?>"><?php echo $team["team_name"]; ?></option>
    <?php } ?>
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序