Php 如何使用codigniter在同一变量post方法名称中插入radio、checkbox和textbox值?

Php 如何使用codigniter在同一变量post方法名称中插入radio、checkbox和textbox值?,php,Php,我的查看页面 <form action="<?php echo base_url()?>Quiz/add_stu_ans" method="POST"> <label>Who is usa president</label> <input type="text" name="answer[]"> <label>Dhoni is cricket player player</label>

我的查看页面

 <form action="<?php echo base_url()?>Quiz/add_stu_ans" method="POST"> 
    <label>Who is usa president</label>
    <input type="text" name="answer[]">

    <label>Dhoni is cricket player player</label>
    <input type="radio" name="answer[]" value="True">True
    <input type="radio" name="answer[]" value="False">False

    <label>Which is asian country</lable>
    <input type="checkbox" name="answer[]" value="newyork">newyork
    <input type="checkbox" name="answer[]" value="india">india
    <input type="checkbox" name="answer[]" value="srilanka">srilanka

</form>
public function add_stu_ans()
    {
     $values['stu_answer']  = $this->input->post('ans');

     $this->Common_model->insert_record('student',$values);
     $this->session->set_flashdata('message_name' , 'Your Data is Inserted');
     redirect('Quiz/question');

  }

这是一款

public function insert_record($table,$values) {     
        $this->db->insert($table,$values);
        return $this->db->insert_id();  
    }

任何人都可以告诉我如何自定义控制器中的代码

只有在您使用另一个隐藏文本字段,其中您的“qstn_id”的值才可能。以数组形式获取此字段

在编码部分,在进行foreach循环时,必须采用“[key]”格式的qstn_id,否则无法找到跳过的记录

例如:

     foreach ($que as $key => $ansValue) {
          $val2 = $ansValue[$key];
      }
// $val2 store as your output.

这是使用json_encode保存数据的代码。让我知道你有任何错误,我没有运行此代码

查看文件

请在结束时检查此项,然后从数据库中获取数据,然后需要通过函数json_decode传递返回的数据

$json_decode_data = json_decode($return_data_from_data_table);

name=“answer[]”
在所有元素中都是相同的,在所有元素中应该是不同的,而不是相同的。但是我的表字段名是answer,因此每个输入值都存储在单列和多行中。然后更改架构。否则,您如何知道哪个问题的答案?问题通过qstn_id循环来自问题表…并且答案表也有一个答案id…如果正确插入答案,我将与两个id进行比较,然后在布尔方法中检查为TRUE或TRUEFALSE@Ameer是否要对所有数据生成json,然后保存到数据?谢谢,但也有复选框值,我如何分割它?先生,谢谢…但问题也是动态方法…所以我如何在不同的变量中提到不同的帖子名称?
public function add_stu_ans()
    {

     $usa_president = $this->input->post('usa_president');
     $cricket_player= $this->input->post('cricket_player');
     $country= $this->input->post('country');

     $final_data = array(
        'usa_president' => $usa_president,
        'cricket_player' => $cricket_player,
        'country' => $country,
     );

     $json_encode_data = json_encode($final_data);

     $this->Common_model->insert_record('student',$json_encode_data);
     $this->session->set_flashdata('message_name' , 'Your Data is Inserted');
     redirect('Quiz/question');

  }
$json_decode_data = json_decode($return_data_from_data_table);