Saturday, 14 September 2013

am using sql code for foreach in codeigniter but there are some small problems

am using sql code for foreach in codeigniter but there are some small
problems

function get_contents() {
$this->db->select('question_no');
$this->db->from('questionnaire');
$this->db->group_by('question_no');
$query = $this->db->get();
$results = $query->result();
//print_r($results);exit;
$result_array = array();
foreach ($results as $row){
$this->db->select_avg('questionnaire.organization_answer_rating');
$this->db->from('questionnaire');
$this->db->where('questionnaire.question_no',$row->question_no);
$query = $this->db->get();
$result = $query->result();
$this->db->select_avg('questionnaire.workgroup_answer_rating');
$this->db->from('questionnaire');
$this->db->where('questionnaire.question_no',$row->question_no);
$query = $this->db->get();
$result1 = $query->result();
$info['question_no'] = $results;
$info['organization_answer_rating'] = $result;
$info['workgroup_answer_rating'] = $result1;
$result_array[]= $info;
echo '<pre>';print_r( $result_array);exit;
}
return $result_array;
}
am using the above code in which when am printing result array am getting
output as
Array
(
[0] => Array
(
[question_no] => Array
(
[0] => stdClass Object
(
[question_no] => 1
)
[1] => stdClass Object
(
[question_no] => 2
)
)
[organization_answer_rating] => Array
(
[0] => stdClass Object
(
[organization_answer_rating] => 3.0000
)
)
[workgroup_answer_rating] => Array
(
[0] => stdClass Object
(
[workgroup_answer_rating] => 3.0000
)
)
)
)
i need to get all these in same array and also one more problem is that am
getting all the questions in db but i need to get particular question_no
in that array. can someone guide me and say me what was the problem and
how to rectify it please. thanks.

No comments:

Post a Comment