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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:33:21+00:00 2026-05-27T02:33:21+00:00

I am running this query using CakePHP: $total = $this->Lapse->query(select sum(unix_timestamp(stop) – unix_timestamp(start)) from

  • 0

I am running this query using CakePHP:

$total = $this->Lapse->query("select sum(unix_timestamp(stop) - unix_timestamp(start)) from lapses where id = ".$lastId."");

And i get back this array structure:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [sum(unix_timestamp(stop) - unix_timestamp(start))] => 1
                )

        )

)

So my variable holds this: $updateVal = $total[0][0][0];

Which isn’t the prettiest, is there a way i can simplify this OTT array?

  • 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-05-27T02:33:22+00:00Added an answer on May 27, 2026 at 2:33 am

    Have you tried the find() method passing a custom fields option?:

    $this->Lapse->find('all', array(
      'fields' => array('sum(unix_timestamp(stop) - unix_timestamp(start)) as elapsed_time'),
      'conditions' => array('Lapse.id' => $lastId),
    ));
    

    The returned array is prettier than the one you’re getting, although it’s not prettier than elapsed_time being an actual model property.

    Another solution would be to set elapsed_time as a virtual field within the model:

    class Lapse extends AppModel {
      ...
    
      public $virtualFields = array(
        'elapsed_time' => 'sum(unix_timestamp(Lapse.stop) - unix_timestamp(Lapse.start)',
      );
    
      ...
    }
    

    Then elapsed_time acts as a model property and would be returned as $updateVal['Lapse']['elapsed_time'] in every find() call.

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

Sidebar

Related Questions

I'm running this query: SELECT TOP 1 [DVD Copy].[Stock No] FROM [DVD Copy] WHERE
SELECT * FROM [makes$] WHERE Corporate Name='Champion Enterprises, Inc.' I'm running this query on
I am running this query select * from measTbl where dateone>'201112100000' and dateone<'202001010000' and
I'm running Mysql 5.0.77 and I'm pretty sure this query should work? SELECT *
I am running a query using a scope and some conditions. Something like this:
in CakePHP how would go about running this query? It's to get the next
I'm using the Entity framework 3.5 and am having trouble running this query. I
When I isolate this query: SELECT `Tagged`.`contact_id` FROM contacts_tags AS Tagged LEFT JOIN tags
Im running this query on the same server as the web application, so SPQuery.ExpandRecurrence
I have problems running a dynamic LIKE statement in my project: this query works

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.