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

  • Home
  • SEARCH
  • 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 9242123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:31:00+00:00 2026-06-18T08:31:00+00:00

I have a tables with many actions, a field is created with the datetime

  • 0

I have a tables with many actions, a field is “created” with the datetime of the action.
I need to get back an array with how many actions I registered per HOUR, WEEK DAY, DAY, MONTH in a periode range.

Is better doing a unique db request and parsing all results

    foreach($scans as $s) {
        $data['total']++;
        $t = strtotime($s['Scan']['created']);
        //week day
        @$data['weekday'][date('w',$t)]++;
        @$data['hour'][date('H',$t)]++;
        @$data['day'][date('d',$t)]++;
        @$data['month'][date('n',$t)]++;
    }

or 5 queries with count() function?
Thanks

  • 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-18T08:31:01+00:00Added an answer on June 18, 2026 at 8:31 am

    A database is equipped to perform exactly this sort of tasks with the best efficiency. You should offload most of data processing to the database system, which will do all sort of optimizations for you, and leave PHP for managing and presentation. In principle you should avoid looping over data in PHP to do processing, unless you are doing presentation stuff.

    So you should do your entire thing in ONE query, and get the final result from your database. Look at your query and try to combine all the things you want into it. Maybe you can try to get help from Stack Overflow if you can’t come up with the right query (but open another question for it).

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

Sidebar

Related Questions

I have created many tables using <table> tag but don't know how to get
I have many tables that use Lookup/Enum references for most of their column values.
I have many tables with identical schemas but different names. Can I create a
I have many tables, say T1, T2, T3. Every table has a column named
I have 2 tables having many to many relation and hence there is junction
I have some tables that benefit from many-to-many tables. For example the team table.
Does anyone has any insight on organizing sqlalchemy based projects? I have many tables
I have two tables with a many to many relationship, through a third table.
hi i have tables like this: Persons: person_id, name then i have many langauge
I have an app where users get points for actions they perform - either

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.