I have a row in table PRVO with four type of values : first, second, third, fourth
I want to count how many occurrences of first and how many of second and how many of third and how many of fourth I have and echo it like this:
First = 4
Second = 5
.....
I have the following code:
$anketadb->select('prvo');
$anketadb->from('anketadata');
$anketadb->group_by('prvo');
How can I add the count to have the result like I wrote above?
Thanks in advance
UPDATE:
Now I have situation:
MODEL:
$anketadb = $this->load->database('anketa',TRUE);
$anketadb->select('prvo');
$anketadb->from('anketadata');
$anketadb->group_by('prvo');
$result = $anketadb->get();
$result = $result->result_array();
$count = array('povremeno' => 0, 'nikad' => 0, 'svakibroj' => 0, 'prodajemkupujem' => 0);
foreach($result as $row){
switch($row){
case 'povremeno' : $count['povremeno']++; break;
case 'nikad' : $count['nikad']++; break;
case 'svakibroj' : $count['svakibroj']++; break;
case 'prodajemkupujem' : $count['prodajemkupujem']++; break;
}
}
return $count;
CONTROLLER:
$this->load->model('anketerezultati_model');
$data['count'] = $this->anketerezultati_model->prvo();
$this->load->view('ankete/rezultatiankete', $data);
VIEW:
echo "povremeno".$count['povremeno'];
echo "nikad".$count['nikad'];
And result is 0 for both… I cannot find the mistake.
Hope you need this:
UPDATE
Finally you have occurrences of first.second…. at
$countarray. To use the number of occurrences$count['first']for second$count['second ']…..