2012-03-26 58 views
0

我有一個表格,從MySQL表中提取數據到一個窗體,每一行都有一個菜單來選擇一個值,我想更新MySQL與選擇每行的每個值時'應用全部「按鈕被點擊,但不起作用。,這裏是我的代碼。更新列表值的MySQL表

<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> 
+0

和setProjectStatus.php中的代碼是什麼? – Elen 2012-03-26 14:47:05

+0

這將有助於很多..我們不能真正幫助你,因爲它似乎所有的魔術都發生在另一頁上;) – snaderss 2012-03-26 14:51:25

+0

這個頁面正在調用自己,,只有這個代碼在頂部...... if isset($ _ POST ['approveAll'])){ \t //連接並選擇一個數據庫 \t require_once(「mysqlConnect.php」); \t \t $ sql =「UPDATE tablename SET projectStatus ='Approved'」; \t mysql_query($ sql); } – user1293274 2012-03-26 15:35:25

回答

0

您試圖重用您的MySQL連接,同時仍然堅持從第一個查詢的結果集。您需要爲內部循環查詢創建第二個連接。更好的可能是使用連接來重寫你的查詢,但是我不能肯定地說不知道你的模式。