表格:插入多值答案(每行一个答案)

时间:2012-11-08 11:37:03

标签: php sql forms post insert

在这种形式下,我可以构建并显示问题和答案(这是我数据库中表格中的值)而没有问题。但是现在我如何插入选择的答案?因为我需要每行插入一个答案,并且答案在一个问题上是多值的。

我想要插入的表具有以下结构:Tbluseranswer ( UserIDFKPK , AnswerIDFKPK , QuestionIDFK , AnswerValue`)

 <?php
    $query_questionset= "SELECT Constructor, QuestionIDFKPK, OnPage, QuestionValue, tblquestionset.SortOrder
    FROM tblquestion, tblquestionset, tbluser
    WHERE tbluser.QuestionSetIDPK = tblquestionset.QuestionSetIDPK
    AND tblquestionset.QuestionIDFKPK = tblquestion.QuestionIDPK
    AND tbluser.UserIDPK = ".@$UserId."
    AND tblquestionset.OnPage= '".@$Screen."'
    ORDER BY tblquestionset.SortOrder";

    $QuestionSet_Constructors = mysql_query($query_questionset);


if(isset($_POST['submit'])){

//Inserts here

}

?>
<html>
<head>
</head>
<body>

<!--BUILDING QUESTIONARE -->

    <?php  while( $row_questionset=mysql_fetch_array($QuestionSet_Constructors)){?> 

            <?php $QuestionID=$row_questionset['QuestionIDFKPK'];   


                    $query_Answer="SELECT * FROM tblanswer WHERE tblanswer.QuestionIDFK = '".@$QuestionID."'";
                    $AnswersValue= mysql_query($query_Answer);

            ?>
        <?php if($row_questionset['Constructor']=="CheckBox"){?>


                <!--SPACE-->
                <div>
                <label class="desc" >
                </label>
                </div>
                <!--/SPACE-->

                        <!--CHECK BOX-->    

                        <div>
                        <label class="desc" name="question" value= "<?php $row_questionset['QuestionIDFKPK'];?>" >
                        <?php echo $row_questionset['QuestionValue']; ?>

                        </label>
                        </div>

                            <!--SPACE-->
                            <div>
                            <label class="desc" >
                            </label>
                            </div>
                            <!--/SPACE-->

                                <fieldset class="checkboxes">
                                <?php while ($row_Answer=mysql_fetch_array($AnswersValue)){ ?>  
                                    <label class="label_check" >
                                    <input name="samplecheckbox"  value="<?= $row_Answer['AnswerValue']; ?>" type="checkbox" />




                                    <?php echo $row_Answer['AnswerValue']; ?>   
                                    </label>    


                                <?php }  ?> 
                                </fieldset>

                        <!--/CHECK BOX-->   

    <!--RADIO BUTTON--> 

                        <div>
                            <label class="desc"name="question" value=" <?php $row_questionset['QuestionIDFKPK'];?>">
                            <?php echo $row_questionset['QuestionValue']; ?>

                            </label>
                        </div>
                            <?php while ($row_Answer=mysql_fetch_array($AnswersValue)){ ?>  
                            <fieldset class="radios">

                                <label class="label_radio">
                                <input name="sample-radio"  value=" <?= $row_Answer['AnswerValue']; ?>" type="radio" checked />
                                <?php echo $row_Answer['AnswerValue']; ?> 
                                </label>
                                <?php   

                                <?php $AnswerId=$row_Answer['AnswerIDPK'];  ?>
                                <?php 
                            <?php }  ?>
                            </fieldset>

                    <!--RADIO BUTTON--> 

        <?php } ?>

    <?php } ?>

    <!--BUILDING QUESTIONARE -->    




<input  name="submit" type="submit"  value="Next &#8594"  >

</form>
</body>
</html>

0 个答案:

没有答案