I want to build a query in model for grouping and counting values in 3 columns (in one MySQL table) with the same type values: INT(11).
Column1 with values: "1" "2" "3".
Column2 with values: "2" "3" "3".
Column3 with values: "1" "1" "1".
Result wanted is an array with 2 parameters: the number and counter for this number.
For example: number "1" and counter "4"
in my CI model:
public function report_1() {
$sql = 'SELECT col1, COUNT(col1) as counter1, col2, COUNT(col2) as counter2,col2,COUNT(col3)
as counter3 FROM table_name GROUP BY ....';
$query = $this->db->query($sql);
return $query->result_array();
}
in my CI View: HTML table with 2 columns ("Number" and "Counter"): Number "1" "2" "3" Counter "4" "2" "3"
Thanks in advance for any solution.