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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:32:19+00:00 2026-06-04T20:32:19+00:00

I have a database that looks like this: (dates are formated with strtotime )

  • 0

I have a database that looks like this: (dates are formated with strtotime)

ID  Date            
1   1338366170000
2   1337761370000
3   1337761370000
4   1337761370000
5   1337156570000
6   1331713370000
7   1331713370000

As you can see some entries are from the same date. I would now like to grab each date and the count how often it occurs.

So the end result would look like:

Date: 1338366170000
Count: 1

Date: 1337761370000
Count: 3

Date: 1337156570000
Count: 1 

Date: 1331713370000
Count: 2 

I am currently doing this to get all dates and count each date:

First I grab all rows:

$stats      = $sql->query("SELECT * FROM stats_clicks");

Now, I think the problems begin when I try to count the entries with same date: I loop through all results and search for each date and count it.

foreach($sql->get() as $result){

    //Sum clicks for each date
    $date   = $result["date"];

    $stats  = $sql->query("SELECT * FROM stats_clicks WHERE date = '$date'");
    $count  = count($sql->get());

    echo "Date: $date<br>Count: $count<br><br>";

}

The output is:

Date: 1338366170000
Count: 1

Date: 1337761370000
Count: 3

Date: 1337761370000
Count: 3

Date: 1337761370000
Count: 3

Date: 1337156570000
Count: 1 

Date: 1331713370000
Count: 2 

Date: 1331713370000
Count: 2 

How can I avoid outputing each date multiple times, but instead each date only once with the correct count?

  • 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-04T20:32:21+00:00Added an answer on June 4, 2026 at 8:32 pm
    SELECT `Date`, COUNT(`Date`) as `Count`
    FROM stats_clicks
    GROUP BY `Date`
    

    Result

    Date    Count
    1331713370000   2
    1337156570000   1
    1337761370000   3
    1338366170000   1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that looks like this: I can generate a tree from
I have data in my database that looks like this: Date (DateTime) Type (varchar)
I have data in an MYSQL database that looks like this: Project Date Time
I have a mysql database that looks like this: |id | city | created
say i have a nvarchar field in my database that looks like this 1,
I have a very simple XML file, that looks like this: <Data><Day Num=4197> <Date>270611</Date>
I have a table in a MSSQL database that looks like this: Timestamp (datetime)
I have a database full of users that roughly looks like this: | id
I have a MySQL Database That Looks like This: Name: Joe Items: 25 CreationDate:
I have a database that look like this: [Invoice] -PK:ID -... [InvoiceDetail] -PK:ID -FK:Invoice_ID

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.