Forum

Thread tagged as: Question, Members

How do I... get a list of Members in JSON format?

Hi,

I'm using the official Members App and looking to list out the members in a table.

Is there any tutorials / best practice tips on how to query the Members table in the database and create a JSON file?

Thanks in advance!

Dan Lee

Dan Lee 1 points

  • 3 years ago

This is how I do it in a micro-app

<?php
    $Members   = new PerchMembers_Members($API);
    $members = $Members->get_by_status('active');

    if (PerchUtil::count($members)) {
        $a = [];

        foreach ($members as $Member) {
            $details = $Member->to_array();
            $last_name = (isset($details['last_name'])) ? $details['last_name'] : $Member->memberID();
            $first_name = (isset($details['first_name'])) ? $details['first_name'] : false;

            $a[strtolower(trim($last_name).trim($first_name)).$Member->memberID()] = $Member;
        }

        ksort($a, SORT_NATURAL);
        $members = $a;
    }
Dan Lee

Dan Lee 1 points

Hi Robert,

Would this file go in the apps folder? Just wondering how I use at the root level of my site.

Thanks for your help!