如何获取多个无线电输入并将其存储在数据库中



注意:这不是任何问题的重复,我需要这个特定问题的答案。

下面是我的视图代码

<?php 
$index = 1;
foreach ($questions as $ques): ?>
<tr>
<td><?php echo $index;?> </td>
<td> <?php echo $ques->question;?> </br>
<div class="custom-control custom-radio">
<input class="custom-control-input" type="radio" id="sdisagree[<?php echo $index;?>]" name="q<?php echo $ques->id;?>" value="1" > 
<label class="custom-control-label" for="sdisagree[<?php echo $index;?>]"> Strongly Disagree
<input class="custom-control-input" type="radio" id="disagree[<?php echo $index;?>]" name="q<?php echo $ques->id;?>" value="2" >  
<label class="custom-control-label" for="disagree[<?php echo $index;?>]">Disagree
<input class="custom-control-input" id="slightlydisagree[<?php echo $index;?>]" type="radio" name="q<?php echo $ques->id;?>" value="3" > 
<label class="custom-control-label" for="slightlydisagree[<?php echo $index;?>]">Slightly Disagree
<input class="custom-control-input" id="slightlyagree[<?php echo $index;?>]" type="radio" name="q<?php echo $ques->id;?>" value="4" > 
<label class="custom-control-label" for="slightlyagree[<?php echo $index;?>]">Slightly Agree
<input class="custom-control-input" id="agree[<?php echo $index;?>]" type="radio" name="q<?php echo $ques->id;?>" value="5" >
<label class="custom-control-label" for="agree[<?php echo $index;?>]"> Agree
<input class="custom-control-input" id="sagree[<?php echo $index;?>]" type="radio" name="q<?php echo $ques->id;?>" value="6" > 
<label class="custom-control-label" for="sagree[<?php echo $index;?>]">Strongly Agree
</td>

</tr>
<?php 
$index++;
endforeach ;?>

这是我的控制器,我想从视图中获得答案。

public function get_answer(){
//i don't know what to write here to get answers from the fields. 
//am i required to use loops? if yes then how?
}

这是我的问题模型和控制器。

从这个控制器中,我从数据库中选择要问的问题。

public function survey_questions(){
$this->load->model("csv_model");
$data['survey'] = $this->csv_model->fetch_survey_questions();
$data["category"] = $this->csv_model->fetch_categories();
$this->load->view("survey_questions", $data);
}

我知道如何从这样的视图中获得单个输入

$variable=$this->input->post("fieldname"(;

然后将其传递给模型。但我在上面的代码中感到困惑,如何从多个收音机中获取数据。

好的我在一个不知名的朋友的帮助下找到了

这就是我需要编写我的控制器的方式。

现在,我静态地放置除"marks_answer"字段之外的所有内容,这是我的问题,即如何动态地执行它。

public function save_student_filled_questionaire(){
$questions = $this->csv_model->fetch_questionaire();
foreach($questions as $q){
$data = array(
'question_id' => $q->id, 
'cat_id' => "1",
'marks_answer' => $this->input->post('q'.$q->id),
'student_id' => "1",
'course_offered_id' => "1",
'batch_id' => "1"
);
$this->db->insert('tbl_survey_answers', $data);

}

相关内容

  • 没有找到相关文章

最新更新