lundi 1 août 2016

If/Else work around in PHP Codeigniter

I have an issue i've been trying to fix for a while now.

$question_session = $this->session->userdata();
    $questions = $question_session['question_details'];
    $answer_data = [];
    if (!empty($questions)) {
        $current_question = $question_session['question_details'][array_rand(($question_session['question_details']))];
         $current_question_key = array_search($current_question, $question_session['question_details']);
        unset($question_session['question_details'][$current_question_key]);
        array_values($question_session['question_details']);
        $this->session->set_userdata('question_details', $question_session['question_details']);
        $current_question['counter'] = $current_question_key + 1;
        $this->load->view('gameplay', $current_question);

        //getting the answers
        $answer = $this->input->post('answer');
        $answers =  array($current_question['_id']=>$answer);

    }

    else{
         //get answer from if condition and validate it.
    }

So, am using the above code to randomly load questions unto a page using. The questions have already been loaded into a session timer. My if statement works well. However, i'm trying to write the else statement such that when the questions in the session is empty(which means user has answered all his questions for the time), i go to another page and get the questions from the if and validate them.

Aucun commentaire:

Enregistrer un commentaire