[TYPO3-english] Show count of users in usergroup

Jigal van Hemert jigal.van.hemert at typo3.org
Sun Dec 29 20:39:35 CET 2013


Hi,

On 28-12-2013 17:50, Miguel wrote:
> No, i'm not asking for someone to do the research for me, only for some
> advices, as i have been searching this for some time, and the little
> information that i have got in english was some talk about that
> snippet... If i have offended someone, i apologize for that.

It's not about offending people but one reason why you don't get much 
response is that there probably was not enough information in your post 
to work with.

> In what concerns about "timed memberships" the information is stored in
> the database fields for example like this " 3|1384252200|1384943400* " .

The "*" at the end worries me a bit. Also, can people be member of more 
than one timed group?

> The first number is what matters to me, because it' the ID of the
> usergroup that the user will belong for the time specified in the rest
> of the field, so the structure is basically this " usergroup id | start
> date | end date | " .
>
> So to acess the id of the usergroup maybe a split will work ?

There is no split function in MySQL. If there is ony one time group 
possible and the syntax is "id|start|end", then you can extract the 
values with:
groupId: SUBSTRING_INDEX(field, '|', 1)
startTime: SUBSTRING(field, LOCATE('|', field), LOCATE('|', field, 
LOCATE('|', field)+1) - LOCATE('|', field) )
endTime: SUBSTRING_INDEX(field, '|', -1)

The query could be something like (I don't know the name of the timed 
usergroup field, so I'll call it "field"):

SELECT COUNT(*) FROM fe_users WHERE
SUBSTRING_INDEX(field, '|', 1) = <groupid> AND
SUBSTRING(field, LOCATE('|', field), LOCATE('|', field, LOCATE('|', 
field)+1) - LOCATE('|', field) ) >= UNIX_TIMESTAMP() AND
SUBSTRING_INDEX(field, '|', -1) <= UNIX_TIMESTAMP()

If a user can be a member of more than one timed user group, I think you 
can only get some result by building a stored function in MySQL or 
perhaps even a User Defined Function.

-- 
Jigal van Hemert
TYPO3 CMS Active Contributor

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the TYPO3-english mailing list