ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Model for extracting member data including custom fields

June 24, 2010 8:20pm

Subscribe [2]
  • #1 / Jun 24, 2010 8:20pm

    Badlands

    17 posts

    Hi, I’m trying to build a module that exports all the members data including custom member fields as a csv file. I would like the field title row to reflect the actual field name, not ‘m_field_id_22’ but rather map the field name ‘m_field_name’ from the ‘exp_memer_fields’ table to the corresponding field in the ‘exp_member_data’ table.

    As you can tell this is quite a complicated query and array to asemble given the abstracted nature of expression engine database fields.

    I am wondering if there is an inbuilt expression engine model that I could tap into to construct this query to help build the correct array for output in CSV formatting?

    Does anyone have any ideas about how best to construct this query?

  • #2 / Jun 24, 2010 8:58pm

    Brandon Jones

    5500 posts

    Hi Badlands,

    If you take a look at the Member module, it does this very thing. Here’s how it does it (I’ve copied the code chunk into its own function for my own use):

    function get_cmf()
    {
        $fields = array();
    
        $query = $this->EE->db->query("SELECT m_field_id, m_field_name FROM exp_member_fields");
    
        if ($query->num_rows() > 0)
        {
            foreach ($query->result_array() as $row)
            {
                $fields[$row['m_field_name']] = 'm_field_id_' . $row['m_field_id'];
            }
        }
    
        return $fields;
    }

    Hope that helps. We may need to move this over to How-to if it doesn’t.  😜

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases