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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:58:30+00:00 2026-06-13T16:58:30+00:00

I would appreciate some help with php arrays. I need to create a graph,

  • 0

I would appreciate some help with php arrays. I need to create a graph, but I can’t seem to get the values from database the way I would like them to.
So basically what I need are hours per month for certain job.
Database looks something like this:

Date       |   Job   | Hours
2012-01-01 |  104    |   8.5

Every job has a different number, but I hope this helps a little.

I need to get the sum of hours per month spent on one job.
So far, I have made an array for months and looped through them:

 $month_date_array = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
 foreach ($month_date_array as $month) {
 $sql = "SELECT * FROM database WHERE date LIKE '%-$month-%'";
 $result = mysql_query($sql) or die (mysql_error());
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      $job[] = $row['job'];
    }
}

Okei, I made some changes and I am going to update my question:
The year does matter, it can’t group 2011 and 2012 together. The year comes from a dropdown menu – the user chooses what year.
Next I added an array of jobs, because I just figured out that I can’t take all jobs, so the job array looks something like this:

$job = array('22', '6', '12', '55');

Basically I would like to know how to get the sum of hours what somebody spent on doing one job per month. And I don’t want to do it with SQL, I need arrays of some sort, because later I have to put together a graph.

  • 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-13T16:58:31+00:00Added an answer on June 13, 2026 at 4:58 pm

    If you want to learn how to manipulate and do this with arrays:

    <?php
    $jobs = array();
    $month_date_array = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
    foreach ($month_date_array as $month) {
        $sql = "SELECT * FROM database WHERE date LIKE '%-$month-%'";
        $result = mysql_query($sql) or die (mysql_error());
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $jobs[$row['job']][$month] += $row['hours'];
        }
    }
    

    But know that this is actually going to group all the years together. In other words November 2011, 2012 and 2013 will be added together if those dates exist.

    You could also do this grouping and adding with SQL only.

    http://sqlfiddle.com/#!2/416d9/5/0

    # Group by Month and Year
    SELECT YEAR(`Date`) as `Year`, MONTH(`Date`) AS `Month`, `Job`, SUM(`Hours`)
    FROM `your_table`
    GROUP BY `Year`, `Month`, `Job`
    

    or http://sqlfiddle.com/#!2/416d9/6/0

    # Group by Month combining the Years
    SELECT MONTH(`Date`) AS `Month`, `Job`, SUM(`Hours`)
    FROM `your_table`
    GROUP BY `Month`, `Job`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would appreciate some help with something I working on and have not done
I would appreciate some help with an UPDATE statement. I want to update tblOrderHead
I would appreciate some help on creating the proper SQL to retrieve only one
I have a problem finding references to this subject and would appreciate some help.
I'm pretty new to Python programming and would appreciate some help to a problem
I'm a newbie in Spring Batch, and I would appreciate some help to resolve
I would really appreciate it if some of you could help optimize my tables,
I need some help please, I have a PHP page with a drop down
I'm not familiar with PHP associate arrays so I'm hoping someone can shed some
I was able to get some help earlier today, but I didn't have everything

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.