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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:57:26+00:00 2026-05-12T05:57:26+00:00

Before I start coding, I want to come up with a good design first.

  • 0

Before I start coding, I want to come up with a good design first. Basically, I have a database table filled with dates, and users who are associated with those dates (the dates are in sql format).

Using PHP I want to, for each user, calculate (count in total) how many weekdays they are associated with, as well as how many weekends they are associated with. I need to have a total count for each month, as well as a grand total. This needs to to “run” from August until May.

I know that I can determine whether a day is a weekend or a weekday with:

 $date = '2007/08/30';
 $weekday = date('l', strtotime($date));

For determining month, I can use SQL, and use a case statement to, for example, get “October” from “10”:

 SELECT MONTH(DATE_SPECIFIED);

What I am most unsure of, though, is what process to go through. I could easily have ALOT of queries, but that’s inefficient. Ideally, I was thinking about printing the results in an html table.

Can anyone offer any suggestions/advice on how you might go about it?

Thanks.


EDIT:

I have a users table, and an eventcal table.

Here is the users table:

 CREATE TABLE `users` (
  `fname` varchar(50) NOT NULL,
  `lname` varchar(50) NOT NULL,
  `role` varchar(75) NOT NULL,
  `region` tinyint(4) unsigned default NULL,
  `username` varchar(25) NOT NULL,
  `password` varchar(75) NOT NULL,
  `new_pass` varchar(5) default NULL,
  PRIMARY KEY  (`username`),
  KEY `role` (`role`),
  KEY `region` (`region`),
  CONSTRAINT `users_ibfk_2` FOREIGN KEY (`region`) REFERENCES `region` (`region`) ON UPDATE CASCADE,
  CONSTRAINT `users_ibfk_1` FOREIGN KEY (`role`) REFERENCES `role` (`role`) ON UPDATE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8

And here is the eventcal table:

 CREATE TABLE `eventcal` (
  `id` int(11) NOT NULL auto_increment,
  `region` tinyint(3) unsigned NOT NULL,
  `primary` varchar(25) NOT NULL,
  `secondary` tinyint(1) NOT NULL,
  `eventDate` date NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `primary_2` (`primary`),
  CONSTRAINT `eventcal_ibfk_1` FOREIGN KEY (`primary`) REFERENCES `users` (`username`) ON DELETE CASCADE ON UPDATE CASCADE
 ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8

Note that evencal.primary has a foreign key reference to users.username…

  • 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-12T05:57:26+00:00Added an answer on May 12, 2026 at 5:57 am

    You should be able to do…. (Assuming you have a date table, a user table, and a link table)

    SELECT MONTH(eventDate), DAYOFWEEK(eventDate), 
    COUNT(*) 
    FROM eventcal as e 
    LEFT JOIN users as u ON e.primary = u.username 
    GROUP BY MONTH(eventDate), DAYOFWEEK(eventDate);
    

    That should return a load of rows, 3 colums each up to 7 rows per month. One is the day index (1 = sunday, 7 = saturday), one is the numeric month and one is the number of users attached to that day.

    If you need to restrict to certain months, you could add a where clause as well like …

    WHERE eventDate BETWEEN '20090501' AND '20091001'
    

    You can also use the WITH ROLLUPS keyword after the group by to have mysql return the totals per day of week or per month as well. But this is often more hassle to use than it saves you, as you have to write logic to determine if the current row is a total or not.

    EDIT:

    If you want to get the weekend/weekday values directly:

    SELECT MONTH(eventDate), IF(WEEKDAY(eventDate)<5, 'weekday', 'weekend') AS DAY,
    COUNT(*) 
    FROM eventcal as e 
    LEFT JOIN users as u ON e.primary = u.username 
    GROUP BY MONTH(eventDate), IF(WEEKDAY(eventDate)<5, 'weekday', 'weekend');
    

    This will return as above but only 2 rows per month, one for weekdays, one for weekends.

    (Although i’m not totaly sure that you can group by a calculated value like this, I think you can – let me know if you try!)

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

Sidebar

Ask A Question

Stats

  • Questions 180k
  • Answers 180k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Turns out that this seems to work: SELECT * FROM… May 12, 2026 at 4:05 pm
  • Editorial Team
    Editorial Team added an answer I tried the answers above, unfortunately it was not simple… May 12, 2026 at 4:05 pm
  • Editorial Team
    Editorial Team added an answer You don't need to check if the iterator is empty.… May 12, 2026 at 4:05 pm

Related Questions

I am currently trying to refactor my codebase for an app I am making,
I want to start writing a http proxy that will modify responses according to
Now, I could go ahead and write this using FileSystemWatcher etc, but before I
I was wondering if there's anyway to layout what I want to code before

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.