Php 选择“仅填写第一行表格”选项

Php 选择“仅填写第一行表格”选项,php,Php,在我的程序中,我从MySql数据库中的数据构建了一个表 <?php while ($row = mysqli_fetch_array($result)) { extract($row);?> <td width="5"> <input name="record_id" hidden value="<?php echo $row['id'] ?>"></td> <td width="75

在我的程序中,我从MySql数据库中的数据构建了一个表

        <?php  while ($row = mysqli_fetch_array($result)) {
    extract($row);?>
    <td width="5">   <input name="record_id" hidden value="<?php echo $row['id'] ?>"></td>
    <td width="75"> <input name="timeneeded" readonly value="<?php echo $row['time_needed']?>"></td>
    <td width="75"> <input name="dateneeded" readonly value="<?php echo $row['date_needed']?>"></td>
    <td width="100"> <input name="firstname" readonly value="<?php echo $row['first_name']?>"></td>
    <td width="100"> <input name="lastname" readonly value="<?php echo $row['last_name']?>"></td>
    <td width="120"> <input name="pickup" readonly value="<?php echo $row['pickup_location']?>"></td>"
    <td width="100"> <input name="dropoff" readonly value="<?php echo $row['destination']?>"></td>"
    <td width='125' align='left'>
    <select size='1' name='assignDrivers' onChange=showDrivers(this.value)>
    <option>Select Driver</option>
    <?php while(list($username)=mysqli_fetch_row($result1)) {
        echo "<option value=\"".$username."\">".$username."</option>";
     }
     ?>
    </select> <input id="drivertouse" name='driver_name' size='15' style='font-weight: 700' value=<?php echo "\"$username\""; ?>> </td>

">"
选择驱动程序

我认为您的问题在于
列表($username)
,您应该能够做到这一点:

while($username = mysqli_fetch_row($result1)) {
   echo "<option value=\"".$username."\">".$username."</option>";
}
while($username=mysqli\u fetch\u行($result1)){
回显“$username.”;
}

$username
变量将作为循环的一部分被重置,因此您不需要使用
list()

试试这段代码,我认为result1查询本身存在问题

 <?php  while ($row = mysqli_fetch_array($result)) {
    extract($row);?>
    <td width="5">   <input name="record_id" hidden value="<?php echo $row['id'] ?>"></td>
    <td width="75"> <input name="timeneeded" readonly value="<?php echo $row['time_needed']?>"></td>
    <td width="75"> <input name="dateneeded" readonly value="<?php echo $row['date_needed']?>"></td>
    <td width="100"> <input name="firstname" readonly value="<?php echo $row['first_name']?>"></td>
    <td width="100"> <input name="lastname" readonly value="<?php echo $row['last_name']?>"></td>
    <td width="120"> <input name="pickup" readonly value="<?php echo $row['pickup_location']?>"></td>"
    <td width="100"> <input name="dropoff" readonly value="<?php echo $row['destination']?>"></td>"
    <td width='125' align='left'>
    <select size='1' name='assignDrivers' onChange=showDrivers(this.value)>
    <option>Select Driver</option>
while($username = mysqli_fetch_row($result1)) {
foreach($username as $user){
   echo "<option value=\"".$user."\">".$user."</option>";
}
}
?>
    </select> <input id="drivertouse" name='driver_name' size='15' style='font-weight: 700' value=<?php echo "\"$username\""; ?>> </td>

">"
选择驱动程序
而($username=mysqli\u fetch\u行($result1)){
foreach($username作为$user){
回显“$user.”;
}
}
?>

仍然只将列表放在第一行,现在返回的不是信息,而是一个包含数组、数组、数组等的列表。您可以发送更多代码吗?-什么是$result1?$username?中存储了什么?。有了这些信息,很可能会有一个解决方案。Hans,最终的工作是将查询结果放入一个数组中,然后在数组中循环执行select语句。感谢您的帮助,它为我指明了正确的方向。很高兴听到这是一个有趣的结果,它为每一行返回了足够的名称,但再次将它们放在第一行的下拉列表中。更新。循环收集驱动程序,并在循环完成后将其转储到外部。谢谢,今天晚些时候我将尝试此功能。此功能已接近,所有选择列表现在都显示,空间大小正确,(表中只有6条记录),但其中没有任何数据,但我可以使用此功能。从表中只提取了一列,名称是“username”(我将在生产中更改它,这是在测试中),list和extract row有什么区别?什么是$result1?$result1是表上查询的结果。查询提取的信息正确-返回的结果与原始代码完全相同。该列表仅显示在第一行中。
<?php
    $the_drivers = ""; // Initialize the drivers variable

    while($username_row=mysqli_fetch_row($result1)) {

    $username = $username_row['username'];

        $the_drivers .= "<option value='" . $username . "'>" . $username . "</option>";
    }

    if(isset($the_drivers)){

        echo $the_drivers;
    }
?>
 <?php  while ($row = mysqli_fetch_array($result)) {
    extract($row);?>
    <td width="5">   <input name="record_id" hidden value="<?php echo $row['id'] ?>"></td>
    <td width="75"> <input name="timeneeded" readonly value="<?php echo $row['time_needed']?>"></td>
    <td width="75"> <input name="dateneeded" readonly value="<?php echo $row['date_needed']?>"></td>
    <td width="100"> <input name="firstname" readonly value="<?php echo $row['first_name']?>"></td>
    <td width="100"> <input name="lastname" readonly value="<?php echo $row['last_name']?>"></td>
    <td width="120"> <input name="pickup" readonly value="<?php echo $row['pickup_location']?>"></td>"
    <td width="100"> <input name="dropoff" readonly value="<?php echo $row['destination']?>"></td>"
    <td width='125' align='left'>
    <select size='1' name='assignDrivers' onChange=showDrivers(this.value)>
    <option>Select Driver</option>
while($username = mysqli_fetch_row($result1)) {
foreach($username as $user){
   echo "<option value=\"".$user."\">".$user."</option>";
}
}
?>
    </select> <input id="drivertouse" name='driver_name' size='15' style='font-weight: 700' value=<?php echo "\"$username\""; ?>> </td>