문제

I have a model named "Myform" and each Myform has 25 questions(questions themselfs does not store in database).Answer for each question store in another table ( table ), so there is one to many relations between form and answers. I want to show each question in my form as an radiobuttonlist and then save or retrieve data to/from database. I know I can show a radiobutton like this:

<?php echo $form->radioButtonList($model,'question', array('1'=>'option1 ', '2'=>'option 2 ', '3'=>'option3 ')); ?>

and to set its value do this:

$model->question='1';

now what should I do to show/save other questions? cause for second, third questions I need something like question2 ,question3 in my second parameter which actually des not exists in the model.

도움이 되었습니까?

해결책

If you want to save 25 answers for each model you need 25 columns in your answers table, where each row represents a record for the the 25 answers.

Your table should have columns id, name (or any other info), answer1, answer2, answer3, and so on.

When you receive the answers you should save it using

$answerModel->answer1 = $_POST['QuestionForm']['question1'];
$answerModel->answer2 = $_POST['QuestionForm']['question2'];
$answerModel->answer3 = $_POST['QuestionForm']['question3'];
... so on ...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top