dssnh86244 2013-08-28 11:44 采纳率: 100%
浏览 102

php mysql中的嵌套循环

I cant update the corresponding edited items. Only the first questions and answers are being updated. I cant get the result that I want. Im stuck on this for a day. Please help me.

Heres the scenario: I have a php file that contains the form and passes it to another php file. a checkbox that has the question id and textboxes that allows them to edit their questions from the database. Every question has its corresponding answers. Also, they can edit them. If they click update button all of the checked questions should be updated. but not all of them is updated. Literally only the first question is the only item that can be updated. Anyone knows whats wrong with my code??

heres a link for the screenshot http://imageshack.us/photo/my-images/706/cetw.png/

Heres my code:

$selected = $_POST['selected'];///the checkbox
$question = $_POST['questiondesc'];


for ($i = 0; $i < sizeof($selected); $i++)
{
    $sql = sprintf("UPDATE exam_questions SET question_description = '%s' WHERE question_id = '%s'", 
           mysql_real_escape_string($question[$i]), 
           mysql_real_escape_string($selected[$i]));
    mysql_query($sql)or die(mysql_error());

    $eren = mysql_query("SELECT * FROM exam_answers WHERE answer_question_set_id = '".$selected[$i]."'")or die(mysql_error());
    while($mikasa = mysql_fetch_array($eren)){}
    $count = mysql_num_rows($eren);

        $answer = $_POST['answerdesc'];
        $answerid = $_POST['ansid'];///answer id



           for($e = 0; $e<$count; $e++){

           $gomugomu = sprintf("UPDATE exam_answers SET answer_description = '%s' WHERE answer_id = '%s'",
           mysql_real_escape_string($answer[$e]), 
           mysql_real_escape_string($answerid[$e]));
           mysql_query($gomugomu)or die(mysql_error());
        }
  • 写回答

1条回答 默认 最新

  • doudihuang7642 2013-08-28 12:07
    关注

    It's a little confusing to understand without a printscreen of your page or something, but it sounds like you have a page that allows multiple checkboxes to be selected at the same time, yet you're only keeping the reference for a single checbox in your $_POST.

    If that's the case, you should be sending the questions' ID's through an array. Please take a look at this accepted answer to see how that can be done: PHP $_POST get data array

    评论

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)