下拉框表仅最后一行有效

时间:2019-05-14 14:14:48

标签: php mysql drop-down-menu

我有一个链接到SQL数据库的下拉列表表。我有2张桌子。第一个是“ talent_table”,这是我试图通过下拉菜单进行编辑的表。第二张表是员工信息。

我正在尝试选择每个框,以将它们发布到另一个PHP文件中。问题是,这仅适用于最后一行(因为它是变量$ row中的最后一行)

如何通过POST从前几行中获取所选项目?

我尝试了在网上找到的各种解决方案,所有这些使我进入了现阶段。如果我只需要表中的一个下拉菜单,则可以使用该下拉菜单,但是由于在while循环中有while循环,因此找不到找到所选值的方法。

<html>
<?php
include_once 'db.php';
$menu   = "talent_table";
$menu2  = "staff_list";
$select = "2";
$res    = mysqli_query($conn, "SELECT * FROM $menu");
$res2   = mysqli_query($conn, "SELECT * FROM $menu2")
?>
<body>
    <style>
<?php include 'style.css'?>
    </style>
    <div>
        <table class="tableFormat">
            <tr>
                <!--<th>id</th>-->
                <th>Key Role</th>
                <th>Currently Held By</th>
                <th>Ready Now</th>
                <th>1-2 Years</th>
                <th>3-5 Years</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
<?php
echo "<form action='Update.php' method='post' class='inputText'>"
?>
<?php while ($row = mysqli_fetch_array($res)): ;?>
            <tr>
                <!--<td></a><?php// echo $row['id'];?></td>-->
                <td>
<?php echo $row['Key_Role'];
    $id2  = $row['id2'];
    $KR   = $row['Key_Role'];
    $CHB  = $row['Currently_Held_By'];
    $RN   = $row['Ready_Now'];
    $Low  = $row['1-2_Years'];
    $High = $row['3-5_Years'] ?>
                </td>
                <td><select name="Current" class="input" onchange="this.form.submit()">
<?php
    $sql = mysqli_query($conn, "SELECT id, Full_Name, Current_School FROM staff_list WHERE id='$CHB'");
    while ($row = $sql->fetch_assoc()) {
        echo '<option value="' . htmlspecialchars($row['Key_Role']) . '">'
        . htmlspecialchars($row['Full_Name'])
            . '</option>';
    }
?>
                        <option></option>
<?php
    $sql = mysqli_query($conn, "SELECT id, Full_Name, Current_School FROM staff_list");
    while ($row = $sql->fetch_assoc()) {
        echo "<option value=" . htmlspecialchars($row['id']) . ">" . htmlspecialchars($row['Full_Name']) . "</option>";
    }
?>
                    </select>
                <td><select name="Ready" class="input">
<?php
    $sql = mysqli_query($conn, "SELECT id, Full_Name, Current_School FROM staff_list WHERE id='$RN'");
    while ($row = $sql->fetch_assoc()) {
        echo "<option value=\"'" . $row['id'] . "'\">" . $row['Full_Name'] . " (" . $row['Current_School'] . ")</option>";
    }
?>
                        <option></option>
<?php
    $sql = mysqli_query($conn, "SELECT id, Full_Name, Current_School FROM staff_list WHERE Key_Role='$KR'");
    while ($row = $sql->fetch_assoc()) {
        echo "<option value=\"'" . $row['id'] . "'\">" . $row['Full_Name'] . " (" . $row['Current_School'] . ")</option>";
    }
?>
                    </select>
                <td><select name="1-2_Years" class="input">
<?php
    $sql = mysqli_query($conn, "SELECT id, Full_Name, Current_School FROM staff_list WHERE id='$Low'");
    while ($row = $sql->fetch_assoc()) {
        echo "<option value=\"'" . $row['id'] . "'\">" . $row['Full_Name'] . " (" . $row['Current_School'] . ")</option>";
    }
?>
                        <option></option>
<?php
    $sql = mysqli_query($conn, "SELECT id, Full_Name, Current_School FROM staff_list WHERE Key_Role='$KR'");
    while ($row = $sql->fetch_assoc()) {
        echo "<option value=\"'" . $row['id'] . "'\">" . $row['Full_Name'] . " (" . $row['Current_School'] . ")</option>";
    }
?>
                    </select>
                <td><select name="3-5_Years" class="input">
<?php
    $sql = mysqli_query($conn, "SELECT id, Full_Name, Current_School FROM staff_list WHERE id='$High'");
    while ($row = $sql->fetch_assoc()) {
        echo "<option value=\"'" . $row['id'] . "'\">" . $row['Full_Name'] . " (" . $row['Current_School'] . ")</option>";
    }
?>
                        <option></option>
<?php
    $sql = mysqli_query($conn, "SELECT id, Full_Name, Current_School FROM staff_list WHERE Key_Role='$KR'");
    while ($row = $sql->fetch_assoc()) {
        echo "<option value=\"'" . $row['id'] . "'\">" . $row['Full_Name'] . " (" . $row['Current_School'] . ")</option>";
    }
?>
                    </select>
                <td><input type="submit" value="submit" class='button'></td>
            </tr>
<?php endwhile;?>
            </form>
        </table><br /><br />
<?php
while ($row = mysqli_fetch_array($res)) {
    echo "$row[id]. $row[Key_Role] <a href='edit.php?edit=$row[id]'>edit</a> <br />";
}
?>
        <script>
        function selectionFunc() {}
        </script>
</body>
</html>

我希望能够在该列的任何下拉列表中更改一个值,并能够通过POST发送该值。

我只能通过POST发送下拉列表的最后一行。

0 个答案:

没有答案