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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:00:36+00:00 2026-05-27T15:00:36+00:00

I have an issue that I can’t solve by myself. The best thing would

  • 0

I have an issue that I can’t solve by myself. The best thing would be if it’s possible to do it directly from mysql but if not, calculating from php is also good.

I have a table that has 3 columns: id, time, value

Now the time value is datetime (example: 2012-11-03 00:13:12)

I want to create statistics from the last 7 days. Let’s say I have 7 rows and today is 2012-12-20.

Here are the rows:
datetime value

2012-12-20 00:12:12 2

2012-12-20 04:06:15 4

2012-12-20 03:12:14 5

2012-12-18 03:12:14 7

2012-12-16 12:12:14 3

2012-12-16 14:23:34 2

2012-12-15 14:23:34 9

If I want to get the last 7 days report, it would be this:

2012-12-14 -> value =0
2012-12-15 -> value =9

2012-12-16 -> value =5

2012-12-17 -> value =0

2012-12-18 -> value =7
2012-12-19 -> value =0

2012-12-20 -> value =11

Currently I have this (extract last 7 day records):

$date=date("Y-m-d");
$date=date ("Y-m-d", strtotime ( '-7 day' . $date ) );  
$qry="select value,date from mytable where date>'$date'";
$res=mysql_query($qry) or die("Couldn't select Information : ".mysql_error());
while($row=mysql_fetch_array($res))
    {
        echo $row["value"];
    }

I hope somebody can help with advice.
Thanks in advance!
Vlad

  • 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-27T15:00:37+00:00Added an answer on May 27, 2026 at 3:00 pm

    This should be relatively easy to solve using just MySQL. This is very similar to this question: MySQL Query GROUP BY day / month / year

    You need to change your query so it gets all the records for a given week.

    SELECT DAY(date) , SUM(value)
    FROM mytable
    WHERE WEEK(date) = WEEK(NOW())
    GROUP BY DAY(date)
    

    Its also very easy to change how you group the numbers, for example by month using GROUP BY MONTH(date). You could also make the MySQL display the day name as a field by doing SELECT DAYNAME(date) For more details on what functions are available check out the MySQL User Guide on Date and Time functions.

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

Sidebar

Related Questions

I'm having an issue that I can't seem to solve myself. I have the
I have an issue in that a Symfony2 form can pass validation but still
I have an nHibernate query issue that looks quite straight forward, but I can't
Having an issue here that I have tried everything I can think of but
I have an issue that I can't seem to solve. I am randomly generating
I have an issue that is driving me nuts and hoping someone can help.
Heyy can somebody help me ? i have this issue that still do know
Happy New Year SO users! I have an issue that I hope someone can
I have list of screen names that can be filtered by letter. The Issue
Strange issue. I have SQL Server running on an EC2 box that I can

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.