1
I have the following:
-- HTML --
<form class="" id="quiz_form" action="" method="post">
   <input type="checkbox" name="mcq-<?php echo $quiz_question['id']; ?>[]" value="<?php echo $key2+1; ?>">
   <input type="checkbox" name="discursive-<?php echo $quiz_question['id']; ?>[]" value="<?php echo $key2+1; ?>">
   <input type="button" onclick="submitQuiz()">
</form>
function submitQuiz() {
    $.ajax({
        url: 'home/submit_av',
        type: 'post',
        data: $('form#quiz_form').serialize(),
        success: function(response) {
            $('#quiz-body').hide();
            $('#quiz-result').html(response);
        }
    });
}
-- Content php receive data post --
public function submit_av($from = "") {
        $data['question_mcq'] = json_encode($this->input->post(NULL, TRUE));
        $data['question_discursive'] = json_encode($this->input->post(NULL, TRUE));
        $this->db->insert('av_results', $data);
    }
In the database is saving so:
{"discursive-8":["My answer 1"],"mcq-7":["1"],"discursive-9":["My answer 2"]}
I need to separate these arrays and place them in their respective fields.
How can I identify inside json_encode if it is" mcq "or" discursive "?
I need to save this way:
Column: question_mcq
{"mcq-7":["1"]}
Column: question_discursive
{"discursive-8":["My answer 1"],"discursive-9":["My answer 2"]}
It is important to remember that values name and value input are not the same, they change within a foreach.