0

I am creating a summary page that shows the number of members in each member group.

I tried the following but it only displays 1 as the result and there are 25 members in this group:

{exp:query sql="SELECT count(*) as active_members from exp_members where group_id=9 "}
    {count}
{/exp:query}

What is the correct syntax for this?

Thanks.

1
  • use {active_members} instead of {count}
    – Jim Wyse
    Jun 5, 2013 at 18:03

1 Answer 1

2

You have a conflict of names of variables. "count" is a reserved name.

On all modules of EECMS, the current item number of a loop is parsed on the variable {count}, starting on 1. If you code a query that returns, let's say, 5 rows, your result would be "12345".

Your query returns just one row. The loop will be executed once and returns "1". Of course, you just need one row. You are already using another name. So use it:

{exp:query sql="SELECT count(*) as active_members from exp_members where group_id=9 "}
    {active_members}
{/exp:query}
3

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.