Skip to content

Instantly share code, notes, and snippets.

@ademers
Forked from engram-design/export.php
Last active July 20, 2018 15:54
Show Gist options
  • Save ademers/4dbb6e7237ea7b4265f2a6d72397fc24 to your computer and use it in GitHub Desktop.
Save ademers/4dbb6e7237ea7b4265f2a6d72397fc24 to your computer and use it in GitHub Desktop.
ExpressionEngine PHP Export into JSON: Members by group
<?php
$group = $_GET['id'];
$content = array();
$entries_query = $this->EE->db->query("SELECT * FROM exp_members WHERE exp_members.group_id = '$group'");
foreach ($entries_query->result_array() as $id => $row) {
$content[$id] = array();
// Remove spaces from EE usernames
$content[$id]['username'] = str_replace(' ', '', $row['username']);
$content[$id]['email'] = $row['email'];
$content[$id]['join_date'] = ($row['join_date']) ? date('Y-m-d H:i:s', $row['join_date']) : '';
$content[$id]['member_id'] = $row['member_id'];
$content[$id]['group_id'] = $row['group_id'];
}
echo json_encode($content);
?>
@john-henry
Copy link

For anybody else that finds this. If you want some of the member profile data along just the member data then you can adapt it like this. Example used is an occupation field in EE member profile

<?php
$group = $_GET['id'];
$content = array();
$entries_query = $this->EE->db->query("SELECT * FROM exp_members as m LEFT JOIN exp_member_data AS d ON d.member_id = m.member_id WHERE m.group_id = '$group'");
foreach ($entries_query->result_array() as $id => $row) {
    $content[$id] = array();
//    Remove spaces from EE usernames
    $content[$id]['username'] = str_replace(' ', '', $row['username']);
    $content[$id]['email'] = $row['email'];
    $content[$id]['join_date'] = ($row['join_date']) ? date('Y-m-d H:i:s', $row['join_date']) : '';
    $content[$id]['member_id'] = $row['member_id'];
    $content[$id]['group_id'] = $row['group_id'];
    $content[$id]['occupation'] = $row['occupation'];
}
echo json_encode($content);
?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment