Posted By

jonathanpglick on 03/17/10


Tagged


Versions (?)

Drupal - get email addresses by role


 / Published in: PHP
 

  1. function _get_emails_by_role( $role ) {
  2. $q = "SELECT u.mail AS email ";
  3. $q .= "FROM {users} u ";
  4. $q .= "INNER JOIN {users_roles} ur ON u.uid = ur.uid ";
  5. $q .= "INNER JOIN {role} r ON ur.rid = r.rid ";
  6. $q .= "WHERE r.name = '%s';";
  7. $db = db_query($q, $role);
  8. $emails = '';
  9. while ($row = db_fetch_object($db)) {
  10. $emails .= $row->email . ', ';
  11. }
  12. return $emails;
  13. }

Report this snippet  

You need to login to post a comment.