多个更新数组查询出错:(


multiple update array query gone wrong :(

嘿,伙计们,我的数组有问题。我只需要查询根据记录id 更新表上的2列

该表有一个名为OffID的列,它查找任何尚未授权的记录。为了将其标记为已授权,用户将选择授权或拒绝复选框,然后按下提交按钮。然而,目前我有9条记录显示在表中,每条记录都有自己的唯一id,但当选择提交时,它只会更新一条。如果有任何帮助表明我哪里出了问题,我们将不胜感激,并提前欢呼:)

好的,我编辑了代码,但它现在才设置第一个记录。因此,如果有8条记录,并且我选择第一条记录接受,第二条记录拒绝,接受和拒绝都设置为数据库中的第一条记录,我的新代码低于

    <?php 
    $path = $_SERVER['DOCUMENT_ROOT'];
    $path .= "/Apollo/dbc.php";
    include_once($path);
    $rs_results = mysql_query("SELECT * FROM off WHERE IsItAuthorised='0' and isitsick='0' ORDER BY DayOff");   
    ?>
    <html>
    <head>
    <title>Administration Main Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <?php
    if (isset($_POST['submit'])) {
        //Assign each array to a variable
        $id = $_POST['id'];
        $approve = $_POST['approve'];
        $deny = $_POST['deny'];
        $limit = count($rs_results); 
    $values = array(); // initialize an empty array to hold the values
        for($k=0;$k<$limit;$k++){
        $msg[] = "$limit New KPI's Added";                  
              $query = "UPDATE off SET Authorised = '$approve[$k]', Deny = '$deny[$k]' WHERE OffID = '$id[$k]'";
        }       
        $Event = "INSERT INTO events (UserName, Event ) VALUES ('$_SESSION[user_name]', 'Entered New KPI' )";
echo $query;
    if (!mysql_query($query,$link)){
            die('Error: ' . mysql_error());
        } else {
            mysql_query($Event);
            echo "<div class='"msg'">" . $msg[0] . "</div>";
        }
        }                             
    ?>
    </head>
    <body>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="14%" valign="top"><?php
    ?>
        </td>
        <td width="74%" valign="top" style="padding: 10px;">
          <p><?php 
          if(!empty($msg)) {
          echo $msg[0];
          }
          ?></p>
          <p>
            <?php 
          $cond = '';   
          $sql = "select * from off ";        
          $rs_total = mysql_query($sql) or die(mysql_error());
          $total = mysql_num_rows($rs_total);         
          ?>        
          <p> 
            <form name "searchform" action="/Apollo/Admin/HolidayRequests.php" method="post">
            <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
              <tr class="mytables"> 
                <td width="4%"><font color="white"><strong>ID</font></strong></td>
                <td width="4%"> <font color="white"><strong>Staff Member</font></strong></td>
                <td width="10%"><font color="white"><strong>Day Off</font></strong></div></td>
                 <td width="10%"><font color="white"><strong>Is It Authorized</font></strong></div></td>
                <td width="15%">&nbsp;</td>
              </tr>
             <tr> 
                <td>&nbsp;</td>
                <td width="10%">&nbsp;</td>
                <td width="17%"><div align="center"></div></td>
                <td>&nbsp;</td>
              </tr>
              <?php while ($rrows = mysql_fetch_array($rs_results)) {?>
              <tr> 
                <td><input name="id[]" id="id[]" size="4" value="<?php echo $rrows['OffID'];?>" /></td>
                <td><?php echo $rrows['StaffMember']; ?></td>
                <td><?php echo date('d/m/Y', strtotime($rrows['DayOff']));?></div></td>
                <td> <span id="approve<?php echo $rrows['id']; ?>"> 
                  <?php if(!$rrows['IsItAuthorised']) { echo "Pending"; } else {echo "Authorized"; }?>
                  </span> </td>
                  <td>
                <input type="checkbox" name="approve[]" id="approve[]" value="1"> Approve
                <input type="checkbox" name="deny[]" id="deny[]" value="1"> Deny

             </td>
              </tr>
              <?php } ?>
            </table>
              <input name="submit" type="submit" id="submit" value="Submit">
          </form>   
          &nbsp;</p>
          <?php  
          ?>
          <p>&nbsp;</p>
          <p>&nbsp;</p>
          <p>&nbsp;</p>
          <p>&nbsp;</p></td>
        <td width="12%">&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>  

这不是因为你的$id etc没有通过一个数组吗:

$id = $_POST['id'];
$approve = $_POST['approve'];
$deny = $_POST['deny'];

您正在使用$_POST['id'],但在您的<form/>中,我看不到任何可以提供数据的<input name="id[]"/>