n3p3 Posted July 10, 2009 Share Posted July 10, 2009 hello everyone, In my script, when a user registers I use a datetime field in db (mysql) to store registration date&time of users. What I want to do is, for my statistics module I want to show daily members count for a time period..for example, date1 - x users date2 - y users date3 - z users ... whats the best way to do this? Thanks Link to comment https://forums.phpfreaks.com/topic/165464-daily-new-members-count/ Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 -- Signups today SELECT count(*) as todays_new_members FROM members m WHERE m.signup_date = NOW() -- Signups this month SELECT count(*) as new_members_this_month FROM members m WHERE month(m.signup_date) = month(now()) -- Signups this year SELECT count(*) as new_members_this_year FROM members m WHERE year(m.signup_date) = year(now()) -- Total signups SELECT count(*) as total_registrations FROM members There are probably better (more performant) solutions. My 666th Post Link to comment https://forums.phpfreaks.com/topic/165464-daily-new-members-count/#findComment-872689 Share on other sites More sharing options...
n3p3 Posted July 10, 2009 Author Share Posted July 10, 2009 thanks for quick response.. How can we show the numbers day by day in the last week for example? Link to comment https://forums.phpfreaks.com/topic/165464-daily-new-members-count/#findComment-872690 Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 Although not sure i think this might pull it off. SELECT * FROM members m WHERE week(m.signup_date, 1) = week(now(), 1) - 1 It's up to your implementation to display it for each and every day. Please note that for mysql the week starts on sunday. Edit: I modified the code now it starts on monday. Link to comment https://forums.phpfreaks.com/topic/165464-daily-new-members-count/#findComment-872691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.