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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:31:52+00:00 2026-05-25T13:31:52+00:00

I have a table with email addresses (colums: id, email, user, date). I’m trying

  • 0

I have a table with email addresses (colums: id, email, user, date). I’m trying to sum email addresses by date then user, which I’m able to do with the below code; but then also sum the total for all users and display it below that date. I’m not sure how to do that… do I need to do another query to total for each date?

$sql = mysql_query("SELECT date, COUNT(email), user FROM emails GROUP BY DATE(date), user");
while ($row = mysql_fetch_array($sql)){
  echo date('m/d', strtotime($row['date'])) . " " . $row['user'] . " " . $row['COUNT(email)'] . "<br />";
}

What I have:

date user count(email)
09/09 29 8
09/09 49 9
09/10 29 4
09/10 49 13
09/11 29 1
09/11 49 3

What I would like:

date user count(email)
09/09 29 8
09/09 49 9
09/09 total 17

09/10 29 5
09/10 49 13
09/10 total 18

09/11 29 1
09/11 49 3
09/11 total 4

Thanks

EDIT: Here’s my code that works:

$sql = mysql_query("SELECT date, COUNT(email), user FROM emails GROUP BY DATE(date), user WITH ROLLUP");

while ($row = mysql_fetch_array($sql)){
  echo date('m/d', strtotime($row['date'])) . " " . (!isset($row['user']) ? 'total' : $row['user']) . " " . $row['COUNT(email)'] . "<br />";
}
  • 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-25T13:31:52+00:00Added an answer on May 25, 2026 at 1:31 pm

    See WITH ROLLUP (a GROUP BY modifier).

    SELECT DATE(`date`) AS date
         , user 
         , COUNT(email) AS cnt
    FROM emails 
    GROUP BY DATE(`date`)
           , user 
    WITH ROLLUP 
    

    would give you:

    date    user   cnt
    09/09   29       8
    09/09   49       9
    09/09   NULL    17
    
    09/10   29       5
    09/10   49      13
    09/10   NULL    18 
    
    09/11   29       1
    09/11   49       3
    09/11   NULL     4
    
    NULL    NULL    39
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql table which will store users email addresses (each is unique
I have an HTML table with one column being email addresses; spambot issues aside,
We have a user table, every user has an unique email and username. We
I have a table: table votes ( id, user, email, address, primary key(id), );
I have a table of users, some of which share an email address. I
I have a SQL Server 2008 table which contains an external user reference currently
A column in my table contains email addresses. I have a text string that
I have a name table with (id,first_name,middle_name,last_name,sex) and an email table with (id_fk,email_add) Infact
I have a table with three fields, FirstName, LastName and Email. Here's some dummy
I have three records in a table example: *Usernames* *email* *city* Nick nick@example.com London

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.