2013-08-27 55 views
0

幫助!我有一個嵌套的記錄集,即問題和答案以及每個問題的相應複選框。如何更新記錄集中的多個值?我應該循環更新查詢嗎?任何幫助將不勝感激。如何在php mysql中更新嵌套記錄集上的多個記錄?

這裏是我的代碼:

<?php 
mysql_select_db($database_iexam, $iexam); 
$query_Recordset1 = "SELECT * FROM exam_questions WHERE question_exam_id = '$exam_id'"; 
$Recordset1 = mysql_query($query_Recordset1, $iexam) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 

do { ?> 
    <tr> 
     <th width="170" scope="col"> 
      <input type="checkbox" name="checkbox" 
        value="<?php echo $row_Recordset1['question_id']; ?>"/> 
      Question: 
     </th> 
     <td colspan="2" scope="col"> 
      <input name="textfield" type="text" 
        value="<?php echo $row_Recordset1['question_description']; ?>" 
        size="50"/></td> 
     <td width="549" colspan="2" scope="col"></td> 
    </tr> 
    <tr> 
     <td>Answers:</td> 
    <?php 
    mysql_select_db($database_iexam, $iexam); 
    $query_Recordset2 = "SELECT * FROM exam_answers WHERE answer_question_set_id = '" . $row_Recordset1['question_id'] . "'"; 
    $Recordset2 = mysql_query($query_Recordset2, $iexam) or die(mysql_error()); 
    $row_Recordset2  = mysql_fetch_assoc($Recordset2); 
    $totalRows_Recordset2 = mysql_num_rows($Recordset2); 

    do { ?> 
     <tr> 
      <td width="170">&nbsp;</td> 
      <td colspan="2"> 
       <input name="textfield2" type="text" size="20" 
         value="<?php echo $row_Recordset2['answer_description']; ?>"/> 
       <input 
        name="<?php echo $row_Recordset2['answer_question_set_id']; ?>" 
        type="radio" 
        value="<?php echo $row_Recordset2['answer_iscorrect']; ?>"/> 
      </td> 
     </tr> 
    <?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?> 
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> 
+0

是的,循環更新查詢 –

回答

0

您可以設置複選框的名字,如姓名=「複選框[]」爲question_id和名稱=「文本框[]」爲question_description最後當您提交此表,您會得到一個這樣的記錄數組,然後你設置一個for循環來獲得單獨的值,並將其更新到數據庫或任何其他地方

+0

怎麼樣?我不知道如何處理這個問題。 –