Hi I have to insert multiple questions and answers,when i click add new question or answer it will append new for like below
Ques 1:
ans 1,
ans 2, > add answer
Ques 2:
ans 1,
ans 2,
ans 3, > add answer
> add question
This is my form structure,and i have two mysql tables for questions and answer separately then i have to insert ques to questions and ans to answers
here is my controller
public function actionAdd_quick()
{
$model=new Question;
$answers=new Answers;
if(isset($_POST['Question']))
{
$model->attributes=$_POST['Question'];
$answers->attributes=$_POST['Answers'];
foreach ($model['questions'] as $value) {
$model=new Question;
$model->questions = $value;
$model->save();
foreach ($answers['answer'] as $ans) {
$answers=new Answers;
$answers->answer = $ans;
$answers->question_id=$model->id;
$answers->save();
}
}
Yii::app()->user->setFlash('add_quick','Thank you for ');
$this->refresh();
}
$this->render('add_quick',array('model'=>$model,'answers'=>$answers));
}
how to do correct foreach for this taskā¦