kwangu

INSERTION OF ANSWER WITH CORRESPONDING QUESTION ID

Aug 19th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. VIEW FILE
  2. Below is the code am using to pull-out questions and its corresponding answers
  3. <ol>
  4.   <ol>
  5.   <?php
  6.   foreach ($questions as $question){
  7.         echo"<input type=\"hidden\" id=\"hiden\" name=\"qid[]\" value=\"$question->id\">";
  8.  
  9.       echo'<li><strong>'.$question->question.'</strong></li>';
  10.      
  11.       foreach($answers as $answer){
  12.          if($answer->question_id === $question->id)
  13.           echo"<input name=\"yankho[".$question->id."]\" type=\"radio\" value=\"$answer->id\"/>".$answer->q_answer."<br />";
  14.           }
  15.       }
  16.   ?>
  17. MODEL
  18. Below is the code am using to insert question id and answer id into the answers table
  19. <?php
  20. public function set_user_answers(){
  21.        $session_data = $this->session->userdata('user_in');
  22.        $id = $session_data['id'];
  23.        $data = array();
  24.     foreach($this->input->post('qid') as $qvalue){
  25.        
  26.          foreach($this->input->post('yankho') as $value){
  27.          
  28.          $data[] = array('question_id' => $qvalue,'selected_answer' => $value,'user_id'=>$id);
  29.             #$this->db->set('cdate', 'now()', FALSE);
  30.            }
  31.         }
  32.      return $this->db->insert_batch('cpd_pretest_answers', $data); 
  33.    }
  34. ?>
Add Comment
Please, Sign In to add comment