Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php mysql中更新嵌套记录集上的多个记录?_Php_Mysql - Fatal编程技术网

如何在php mysql中更新嵌套记录集上的多个记录?

如何在php mysql中更新嵌套记录集上的多个记录?,php,mysql,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_Re

救命啊!我有一个嵌套的记录集,即问题和答案以及每个问题对应的复选框。如何更新记录集中的多个值?我要循环更新查询吗?任何帮助都将不胜感激

这是我的密码:

<?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)); ?>

您可以为问题id设置name=“checkbox[]”等复选框名称,为问题描述设置name=“textfield[]”等复选框名称,最后,当您提交此表单时,您将获得一个记录数组,然后设置for循环以获取单独的值并将其更新到数据库或任何位置

是的,循环更新查询如何?我不知道如何处理这件事。