使用列表值更新mysql表

时间:2012-03-26 14:43:29

标签: php

我有一个从mysql表中提取数据到表单的表单,每行都有一个菜单来选择一个值,我想更新mysql,当点击'Apply To All'按钮时,为每一行选择每个值但根本不起作用。这是我的代码。

<td><form id="main" name="main" method="post" action="setProjectStatus.php" onsubmit="return validateMain();">
      <table width="100%" cellspacing="1" cellpadding="1">
        <tr>
          <td width="35%" rowspan="3"><img src="../img/project.jpg" alt="Comp Sci Stud" width="325" height="199" border="2" /></td>
          <td width="65%" height="42" colspan="2"><table width="94%" cellpadding="1" cellspacing="1" class="main_table">
            <tr class="table_title">
              <td width="100%" class="table_title">Set Project Status. </td>
              </tr>
            <tr>
              <td height="26">&nbsp;</td>
              </tr>
            <tr>
              <td height="26"><table width="100%" cellspacing="1" cellpadding="1">
                <tr class="table_head">
                  <td width="2%" height="35"><div align="center"></div></td>
                  <td width="26%" height="35"><div align="center">Student Name</div></td>
                  <td colspan="2"><div align="center">Project</div></td>
                  <td width="19%"><div align="center">Status</div></td>
                </tr>
<?php
 session_start();
 $username = $_SESSION['username'];

 require_once("mysqlConnect.php"); 

//
$sql="SELECT * FROM spms_Student";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

echo "There are $count projects to be undertaken.";
while($rows=mysql_fetch_array($result)){
//
$query = "SELECT name FROM spms_systemUser WHERE userId = '".$rows[0]."'";
$result1 = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result1);
$name = $row[0];
?>

                <tr>
                  <td height="25" align="center">&nbsp;</td>
                  <td align="center"><?php echo $name; ?></td>
                  <td colspan="2" align="center"><?php echo $rows[1]; ?></td>
                  <td align="center"><label>
                    <select name="select" class="form_field_100px_select">
                      <option value="Pending" selected="selected">Pending</option>
                      <option value="Approved">Approved</option>
                      <option value="Disapproved">Disapproved</option>
                    </select>
                  </label></td>
                </tr>
<?php
}
?>
                <tr class="pager_bg">
                  <td height="35">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td width="37%" align="right"><input name="done" type="button" id="done" value="Done" onclick="window.location='../coordinatorMenu.html'" /></td>
                  <td width="16%"><label>
                    <input name="approveAll" type="submit" id="approveAll" value="Approve All" />
                  </label></td>
                  <td><input name="apply" type="submit" id="apply" value="Apply To All" /></td>
                </tr>
<?php
mysql_close();
?>
              </table></td>
            </tr>
          </table></td>
          </tr>
        <tr>
          <td colspan="2">&nbsp;</td>
          </tr>

        <tr>
          <td colspan="2"><label></label>            <label></label></td>
          </tr>
      </table>
    </form></td>

1 个答案:

答案 0 :(得分:0)

您正在尝试重用MySQL连接,同时仍然保留第一个查询的结果集。您需要为内循环查询创建第二个连接。更好的方法可能是使用连接重写您的查询,但在不知道您的模式的情况下我无法肯定地说。