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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:18:17+00:00 2026-06-12T06:18:17+00:00

I have a problem with my php query for getting data. Let me explain

  • 0

I have a problem with my php query for getting data. Let me explain what I want. I have a database which saves the active users for some hours in a day. For example 01-01-2012 13:00
active = 5 01-01-2012 14:00 active = 10. My php query should make an array which contains 2 columns which are date and active. But date must be like 01-01-2012 withour hours. So I grouped them as date2 but I couldn’t find the active(sum) for each days. Here is my query which doesn’t give the right active sums.

$query2 = mysql_query("SELECT DATE_FORMAT(date, '%Y-%m-%d') AS date2, SUM(active) FROM hit WHERE game= '".$game."' AND source = '".$source."' AND date > '".$dateFrom."' AND date < '".$dateTo."' GROUP BY date2 ORDER BY date2");

while($tuple=  mysql_fetch_array($query2)){
    $myArr[] = $tuple;
}
print_r($myArr);
  • 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-12T06:18:18+00:00Added an answer on June 12, 2026 at 6:18 am

    You need to alias SUM(active) and GROUP BY date. If date is a datetime, you can GROUP BY DATE(date). Also, be careful with reserved words and make sure to use tick marks where necessary.

    Further, if you are looking for an inclusive date range, you should know that when you send 2012-10-03, it is actually 2012-10-03 00:00:00 and any records between 00:00:00 and 23:59:59 will be ignored.

    Lastly, you should stop using mysql_ functions as they are being deprecated.

    This query should work:

    $query2 = mysql_query("
        SELECT DATE_FORMAT(`date`, '%Y-%m-%d') AS date2, SUM(active) AS active 
        FROM hit 
        WHERE game= '".$game."' AND source = '".$source."' 
            AND `date` > DATE_SUB('".$dateFrom."', INTERVAL 1 SECOND) 
            AND `date` < DATE_ADD('".$dateTo."', INTERVAL 1 DAY) 
        GROUP BY DATE(`date`)
        ORDER BY `date`");
    $i = 0;
    while($tuple=  mysql_fetch_array($query2)){
        $myArr[$i][date2] = $tuple[date2];
        $myArr[$i][active] = $tuple[active];
        $i++;
    }
    print_r($myArr);
    

    Your array ($myArr) would then look something like:

    Array
    (
        [0] => Array
            (
                [date2] => 2012-10-03
                [active] => 5
            )
    
    )
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a serious problem with getting data from a sql query in php
I have a problem. I have 2 php scripts, one which sends xml data
I have a problem in php code inserting values into database (I use PHPMyAdmin).
I currently have a problem within PHP where I want to sort these posts
i have a problem using some php functions on a string i get from
i have problem.. for(a=1;a<10;a++){ $(.div).append(<div id=+a+></div>) $.ajax({ url: file.php, data: a=+a, type: POST, async:
I have a html page that calls a php object to get some data
I have a block of code below which inserts data into database using mysqli
I'm getting data into my database without any problem using mysql_real_escape_string. So an entry
i have created custom query which i am sending via POST ajax but problem

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.