Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:28:46+00:00 2026-06-13T02:28:46+00:00

I have a row in table PRVO with four type of values : first,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:28:47+00:00Added an answer on June 13, 2026 at 2:28 am

    Hope you need this:

    $this->db->select('*');
    $this->db->from('anketadata');
    $this->db->group_by('prvo');
    $result =   $this->db->get();
    
    //Result set
    $result =   $result->result_array();
    

    UPDATE

    $count  =   array('first' => 0, 'second' => 0, 'third' => 0, 'fourth' => 0);
    
    foreach($result as $row){
    
        switch($row['<fieldName>']){
    
            case 'first' :  $count['first']++; break;
            case 'second' : $count['second']++; break;
            case 'third' :  $count['third']++; break;
            case 'fourth' : $count['fourth']++; break;
        }
    }
    

    Finally you have occurrences of first.second…. at $count array. To use the number of occurrences $count['first'] for second $count['second ']…..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my html table I have two row, first row having no css but
I have a table row with 5 cells. I want to click an image
I have a table row and I tried many things to change its color
I have a row in a table that I do not want to be
Say i have a table row with the two text boxes and i want
I have a table row, and within that, I have a td (whatever it
I have a table row with 4 columns on my ecommerce site and I
I have a table row that needs to be hidden when the anchor with
I have a table row that has the error message in it. <tr runat=server
We have a 10 thousand row table that has just 2 columns, a primary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.