php - Looping over with arrays by grouping matching values -


i writing module website, gives breakdown of test results, need someout put similar this,

test title
average mark 85%

test title 2
average mark 12%

the array getting database looks this,

    array (     [0] => array         (             [result_id] => 11             [test_taken] => 2011-10-04 16:22:59             [mark] => 5             [retaken] => false             [tests_test_id] => 4             [test_title] => website development css basics             [test_slug] => website-development-css-basics             [mark_needed] => 90             [retake] => yes             [topic_id] => 402             [topics_topic_id] => 402         )      [1] => array         (             [result_id] => 12             [test_taken] => 2011-10-04 16:30:02             [mark] => 50             [retaken] => false             [tests_test_id] => 5             [test_title] => test             [test_slug] => another-test             [mark_needed] => 10             [retake] => no             [topic_id] => 402             [topics_topic_id] => 402         )  ) 

this query currently,

$this->db->select('results.result_id, results.test_taken, results.mark, results.retaken, results.tests_test_id, tests.test_title, tests.test_slug, tests.mark_needed, tests.retake, topics.topic_id, tests.topics_topic_id')     ->from('results')     ->join('tests', 'tests.test_id = results.tests_test_id', 'left')     ->join('topics', 'topics.topic_id = tests.topics_topic_id', 'left');      $query = $this->db->get();     return $query->result_array(); 

i need somehow group results have same test id can mean average of results using mark key.

is possible in php?

this kind of thing should database you. along lines of:

select avg(mark) test_results group tests_test_id 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -