2

I'd like to be able to display the number of "active" members on a site. Ideally this would be something like "number of members who have logged in in the past 30 days".

Barring that, I'd settle for the total number of combined members in a set of member groups, like: group_1 + group_3 + group_5 = total number of members.

What do you think is the best way of going about this?

1 Answer 1

4

So both of the above should done done relatively easy with the query tool...

The SQL you'll need is :

SELECT count(*) as active_members from exp_members WHERE FROM_UNIXTIME(last_visit) > DATE_SUB(NOW(), INTERVAL 30 DAY);

The second one would just be :

SELECT count(*) as active_members from exp_members where group_id=1 OR group_id=3 OR group_id=5;

You'll simply be able to get the value using {active_members} from within the Query module.

Hope this helps.

2
  • A small edit in the first query of above answer: SELECT count(*) as active_members from exp_members WHERE FROM_UNIXTIME(last_visit) > DATE_SUB(NOW(), INTERVAL 30 DAY); as last_visit is being stored as unit timestamp. Apr 12, 2013 at 16:09
  • use WHERE group_id = '1' OR group_id = '3' OR group_id = '5' Using AND will return 0 for active_members. You can't be a member of all 3 groups at once.
    – Jim Wyse
    Apr 12, 2013 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.