Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VIEW FILE
- Below is the code am using to pull-out questions and its corresponding answers
- <ol>
- <ol>
- <?php
- foreach ($questions as $question){
- echo"<input type=\"hidden\" id=\"hiden\" name=\"qid[]\" value=\"$question->id\">";
- echo'<li><strong>'.$question->question.'</strong></li>';
- foreach($answers as $answer){
- if($answer->question_id === $question->id)
- echo"<input name=\"yankho[".$question->id."]\" type=\"radio\" value=\"$answer->id\"/>".$answer->q_answer."<br />";
- }
- }
- ?>
- MODEL
- Below is the code am using to insert question id and answer id into the answers table
- <?php
- public function set_user_answers(){
- $session_data = $this->session->userdata('user_in');
- $id = $session_data['id'];
- $data = array();
- foreach($this->input->post('qid') as $qvalue){
- foreach($this->input->post('yankho') as $value){
- $data[] = array('question_id' => $qvalue,'selected_answer' => $value,'user_id'=>$id);
- #$this->db->set('cdate', 'now()', FALSE);
- }
- }
- return $this->db->insert_batch('cpd_pretest_answers', $data);
- }
- ?>
Add Comment
Please, Sign In to add comment