普通网友 2012-03-29 13:30
浏览 15
已采纳

进入新页面时如何将号码恢复为1

I have a problem with my application. First of all on a previous page the teacher types in the number of sessions (exams) he or she wants to create and types in the number of questions they want per session.

Now on the current page, If I have multiple sessions or exams in other words, then lets say I am on the first exam, it will let me add question numbers for the first exam. Now If I submit the form then it will take me to the second session and I have to add new question numbers in from scratch. Now if I try to add a question number a question number, then it does not add a question number into the table.

I have figured out where the problem occurs. The problem occurs in the code below:

if (qnum > <?php echo (int)@$_POST['textQuestion']; ?>) {
    return;
}

What I have stated above is that if the number of questions added, is more than the number of questions stated on the previous page, then do not add question number. So lets say I have 2 sessions and I want only 1 question per session. In the first session it adds question number 1, but when I get to second session, it doesn't add question number 1 for second session because it thinks it is question number 2, even though it is suppose to be question 1 for second session.

So how do I get it so that if user goes to second session, it knows that the question number starts back at 1?

Below is full code on how question number is added into a table:

  var qnum = 1;
    var count = 1;

    function insertQuestion(form) {   

        if (qnum > <?php echo (int)@$_POST['textQuestion']; ?>) {
        return;
    }


        var $tbody = $('#qandatbl > tbody'); 
        var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
        var $qid = $("<td class='qid'>" + qnum + "</td>");

        $tr.append($qid);
        $tbody.append($tr); 

        count++;


        $(form).find('.numberOfQuestions').val(qnum);

        ++qnum;
        $("#questionNum").text(qnum);  


}
  • 写回答

1条回答 默认 最新

  • doukao2180 2012-03-29 13:33
    关注

    Try to use $_SESSION instead of $_POST. Anyway, using @ is a bad habit.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?