i have make statistics - compare 2 values. have made 2 queries.now looks that:
these progressive bars repeat many times. should 1 progressive bar each question. these statistics show results survey. have divide average answer of student each question survey average answer of students have filled survey question. , i'm trying make 2 foreach loops these 2 queries. repeat many times. how should use them together? i'm using codeigniter. view is:
<?php foreach ($average_result $row) { echo "<h4 id='question_name'> question </h4>"; $percent_average=(round("$row->answer",2)*20); $point=round("$row->answer",2); echo "<br/>"; foreach($average_student_result $average) { $average_result = round("$average->answer",2); $percent=(round("$average->answer",2)*20); ?> <div class="progress"> <div class="progress-bar" role="progressbar" style="width: <?php echo round($percent_average,2); ?>%;"> <?php echo (round($average_result,2)/round($point,2)); echo "<br/>"; ?> </div> </div> <?php } } ?>
my controller is:
public function average_results_show() { $data['dynamic_view'] = 'results/average_results'; $data['average_student_result'] = $this->result_model->average_student_result(); $data['average_result'] = $this->result_model->result_question(); $this->load->view('templates/main',$data); }
my model is:
/* show average answers of questions of student */ public function average_student_result() { $this->db->select('survey_questions.question'); $this->db->distinct('survey_questions.question_id'); $this->db->select_avg('answer'); $this->db->from('survey_answers'); $this->db->join('survey_questions', 'survey_questions.question_id= survey_answers.question_id '); $this->db->where('user_id', $this->session->userdata['user_id']); $this->db->where('survey_id', $this->uri->segment(3)); $this->db->group_by('survey_answers.question_id'); $query=$this->db->get(); return $query->result(); } /* show average answers of questions */ public function result_question() { $this->db->select('survey_questions.question'); $this->db->distinct('survey_questions.question_id'); $this->db->select_avg('answer'); $this->db->from('survey_answers'); $this->db->join('survey_questions', 'survey_questions.question_id= survey_answers.question_id '); $this->db->where('survey_id', $this->uri->segment(3)); $this->db->group_by('survey_answers.question_id'); $query=$this->db->get(); return $query->result(); }
from top foreach can question id feel. in $average_student_result array getting particular student answered questions array
$average_student_result['question_id'] = 'answer average or answer'; //any value
so can avoid inside foreach $average_student_result[$row->question_id]
. getting both per student wise overall students wise also. hope answer help.
Comments
Post a Comment