php - How to display monthwise and week wise records in case of following scenario? -


i'm using php , mysql in website. there 1 table in database named users. has 2 fields viz.user_reg_date(bigint(12)) , user_last_login(bigint(12)). these 2 fields store date in unix timestamp format. whole table structure follows:

user_id         varchar(32) user_title      enum('mr', 'ms', 'mrs') user_first_name varchar(50) user_last_name  varchar(50) user_name   varchar(100) user_password   varchar(50) user_email  varchar(150) user_dob    date     user_hybridauth_p_name  varchar(100) user_hybridauth_p_uid   varchar(100) user_reg_date   bigint(12) user_status     enum('enable', 'disable') user_subscription   enum('lifetime', 'period') user_update_date    bigint(12) user_last_login     bigint(12) user_last_activity  bigint(12) user_created_staff_id   varchar(32) user_updated_staff_id   varchar(32) user_registered_type    enum('online', 'manual') 

now want display record counts i.e. count of users user_reg_date falls within dates of current week record count of users user_last_login falls within dates of current week. other queries required display such record counts of last week last 2 weeks current date. want display same record counts monthwise. can me in achieving this? in advance. ried fetch such counts between 2 dates worked extent. giving me date wise count of user_reg_date not count of users last logged in. i'm not able write perfect queries. query written follows :

    select date( from_unixtime( user_reg_date ) ) 'current date', count( user_reg_date ) 'registered_user_count', count( user_last_login ) 'logged_in_count' users user_reg_date >=1341100800 , user_reg_date <=1374451200 , user_last_login >=1341100800 , user_last_login <=1374451200 group date( from_unixtime( user_reg_date ) ) , date( from_unixtime( user_last_login ) )  

you can this

select   (select count(*)       users     user_last_login between unix_timestamp(adddate(curdate(), interval 1-dayofweek(curdate()) day))                               , unix_timestamp(adddate(curdate(), interval 7-dayofweek(curdate()) day))   ) logged_in_count,   (select count(*)       users     user_reg_date   between unix_timestamp(adddate(curdate(), interval 1-dayofweek(curdate()) day))                               , unix_timestamp(adddate(curdate(), interval 7-dayofweek(curdate()) day))   ) registered_user_count 

here sqlfiddle demo


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -