English 中文(简体)
对应数字并不正确。
原标题:It is not display correct numbers in the echo

我的INSERT VALUES有问题。 问题在于我尝试并插入问题编号。 我要说的是,我试图插入两个问题。 首先,问题数目(问题)应为1,而第二个问题应为2。

但问题是,这两个问题在INSERT VALUES时显示问题3。 因此,它为每个问题所做的工作是,插入下一个问题编号,例如所有问题3。

以下是我重复问答2个问题时所显示的情况:

INSERT INTO Question (QuestionId, QuestionContent) VALUES ( 3 , what is my name ), ( 3 , what is my age ) 

上述情况是不正确的。 下面是它应当重复的:

INSERT INTO Question (QuestionId, QuestionContent) VALUES ( 1 , what is my name ), ( 2 , what is my age ) 

因此,我想知道的是,我如何能够对每个问题显示正确的问题编号,因此,在正确的次序中,应当从问题1、2、3等增加正确的问题号。

下面是“javascript Code and form Code”,其中将问题列入表格。 用户将问题列入表格。 当用户对问题1和问题提出第一个疑问时,当他们回答第二个问题时,就会回答问题2和问题等。

<script>

    function insertQuestion(form) {   

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


    $( .questionTextArea ).each( function() {

    var $this = $(this);
    var $questionText = $("<textarea class= textAreaQuestion ></textarea>").attr( name ,$this.attr( name )+"[]")
                   .attr( value ,$this.val())

    $question.append($questionText);

    });

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

    }

    ++qnum;
    $(".questionNum").text(qnum);
    $(".num_questions").val(qnum);

</script>


<form id="QandA" action="insertQuestion.php" method="post" >

<table id="question">
<tr>
    <th colspan="2">
        Question Number <span class="questionNum">1</span>
        <input type="hidden" class="num_questions" value="" name="numQuestion">
    </th>
</tr>
<tr>
    <td rowspan="3">Question:</td> 
    <td rowspan="3">
        <textarea class="questionTextArea" rows="5" cols="40" name="questionText"></textarea>
    </td>
</tr>
</table>

</form>

以下是INSERT VALUES。 我怎么能正确显示南问题。 由于我在为第一次考试提出问题后可能举行两次考试,我无法做简单的算术,在第二次考试中,我需要从一次问题开始,以便我认为正确显示南问题更好。

    $i = 0;
$c = count($_POST[ gridValues ]);

$insertquestion = array();

for($i = 0;  $i < $c; $i++ ){

    switch ($_POST[ gridValues ][$i]){

    case "3": 
    $selected_option = "A-C";
    break;

    case "4": 
    $selected_option = "A-D";
    break;

    default:
    $selected_option = "";
    break;

    }      

    $optionquery = "SELECT OptionId FROM Option_Table WHERE (OptionType =  ". mysql_real_escape_string($selected_option)." )";
    $optionrs = mysql_query($optionquery);
    $optionrecord = mysql_fetch_array($optionrs);
    $optionid = $optionrecord[ OptionId ]; 

    $insertquestion[] = " ". 
                    mysql_real_escape_string( $_POST[ numQuestion ] ) ." , ".  
                    mysql_real_escape_string( $_POST[ questionText ][$i] ) ." , ".  
                    mysql_real_escape_string( $optionid ) ." ";

}

 $questionsql = "INSERT INTO Question (SessionId, QuestionId, QuestionContent, QuestionMarks, OptionId) 
    VALUES (" . implode( ), ( , $insertquestion) . ")";

echo($questionsql);


mysql_close();

问题回答

如果它是一个主要的关键,那么它就离开了外地,就像它一样。

INSERT INTO Question (QuestionContent) VALUES ( what is my name ), ( what is my age )

it will automatically assign the id to the question. When you get data to display you can simply use a variable to produce question numbers. You will have to avoid using id as question number.

您必须主动提出这些问题。 在数据库中尝试使用自动加固顺序。 你在这里混淆了一些事情。 您在数据库中需要一个独特的标识,这不同于您前身的表格数量。 另外,如果你有不同问题的考试,你应有两个桌子,一个是参加考试,一个是用汽车加油,另一个是提及考试的外国钥匙持有问题。 在这种情形下,你必须承诺回答问题,但只是询问问题名称(和考试参考资料),该数据库将产生你的意见。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签