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 8251575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:16:58+00:00 2026-06-08T00:16:58+00:00

I am trying to show some stats given date ranges. In table rows there

  • 0

I am trying to show some stats given date ranges. In table rows there are many ID’s and trying to calculate total minutes of it’s own ID.

Currently returns values as below:

{"id":"25","minute":13}
{"id":"17","minute":12}
{"id":"16","minute":10}
{"id":"17","minute":10}
{"id":"16","minute":4}
{"id":"34","minute":5}
{"id":"17","minute":21}
{"id":"30","minute":12}
{"id":"30","minute":13}
{"id":"30","minute":50}

Controller

public function actionStats()  {
    if (isset($_POST['begin'], $_POST['end'])) {
        $begin = strtotime($_POST['begin']);
        $end = strtotime($_POST['end']);

        $Criteria = new CDbCriteria();
        $Criteria->condition = "created >= $begin and  created <= $end and status=1";
        $transcripts = Transcripts::model()->findAll($Criteria);

        foreach($transcripts as $transcript)  {
            $op = $transcript->opID;
            $minute = $transcript->ended - $transcript->created;

            echo json_encode(array("id" => $op, "minute" => floor($minute/60)));
        }
    }       
}
  • 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-08T00:17:00+00:00Added an answer on June 8, 2026 at 12:17 am

    I’d modify your code to look like:

    public function actionStats()
    {
    
        if (isset($_POST['begin'], $_POST['end']))
        {
            $begin = strtotime($_POST['begin']);
            $end = strtotime($_POST['end']);
    
            $Criteria = new CDbCriteria();
            $Criteria->condition = "created >= $begin and  created <= $end and status=1";
            $transcripts = Transcripts::model()->findAll($Criteria);
    
            $transcriptTotals = array();
            foreach($transcripts as $transcript)
            {
    
                $op = $transcript->opID;
                $minute = $transcript->ended - $transcript->created;
                if (array_key_exists($op, $transcriptTotals)) {
                    $transcriptTotals[$op] += floor($minute/60);
                } else {
                    $transcriptTotals[$op] = floor($minute/60);
                }
            }
            echo json_encode($transcriptTotals);
        }       
    
    }
    

    This should result in output that looks like:

    {'1':'2', 'id':'sumOfMinutes', etc}
    

    If your JSON needs to be like you specified above, you would have code like:

    foreach ($transcriptTotals as $id=>$sum) {
        echo json_encode(array('id'=>$id, 'minutes'=>$sum));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've trying to create some stats for my table but it has over 3
I am trying to show some videos on a website using HTML5. On my
I am trying to show some news in the home screen and I have
i'm trying to hide/show some control on a page from Page_LoadComplete. If a put
I'm trying to show programmers that some captchas are too weak, and i'm breaking
I am trying to use highcharts to show some data over the last 24
My program displays an ABAP list, I'm trying to show a header (some lines
I am trying to plot some test data (show at the end of this
I'm trying to make a generic Search UserControl that can be given some values,
I'm trying to show or hide some xml using Apache Server Side Includes logic

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.