How to select only users from a certain user group and export them to CSV?

goliath 11 Jun, 2014
How can I select the users (or their email addresses) from a certain user group and export them to a CSV file?

Let me explain: I have different users and different user groups created in Joomla. I want to export the user email addresses from one certain user group to a CSV file.

With ChronoForms I am able to export all of the users with the CSV Export function. But how can I do this for the email addresses of one certain user group?
goliath 11 Jun, 2014
I thought a 'custom code' action with the following -followed by the 'CSV Export' action- would do the trick, but not so:

SELECT id, email
FROM web_users
WHERE id IN
( SELECT user_id
FROM web_user_usergroup_map
WHERE value = 14
);
goliath 12 Jun, 2014
WHERE value = 14 needs to be WHERE group_id = 14
But still no effect...
goliath 12 Jun, 2014
I executed this code via phpMyAdmin and this works.

SELECT id, email FROM web_users WHERE id IN ( SELECT user_id FROM web_user_usergroup_map WHERE group_id = 14 )

So how do I integrate this into ChronoForms?
GreyHead 12 Jun, 2014
Answer
Hi geertmartens,

I'd probably add the query to a Custom Code action
<?php
$db = JFactory::getDBO();
$query = "
  SELECT `id`, `email`
    FROM `web_users`
    WHERE `id` IN ( SELECT `user_id` FROM `web_user_usergroup_map` WHERE `group_id` = 14 )
";
$db->setQuery($query);
$form->data['user_list'] = $db->loadAssocList();
?>

Bob
This topic is locked and no more replies can be posted.