I'm creating a custom member field programmatically. This works fine, except that I want the database column to be dynamic based on what's already in the database.
In my code below, the uniqueFieldId variable could be 2, or 5, or even 999. This should be based on the columns that are already in the database. When m_field_id_2 and m_field_id_3 exist in the database, uniqueFieldId should be 4 so that the function below adds the column m_field_id_4 to the database.
How can I do this?
private function create_custom_member_field()
{
//ToDo: Find a way to calculate the columns, not the rows.
$uniqueFieldId = ...;
// Add new columns in the member_data table
ee()->dbforge->add_column('member_data', array('m_field_id_' . $uniqueFieldId => array('type' => 'text')));
ee()->dbforge->add_column('member_data', array('m_field_ft_' . $uniqueFieldId => array('type' => 'tinytext')));
// Add the actual credits field
ee()->db->insert('member_fields', array('m_field_id' => $uniqueFieldId,
'm_field_name' => 'credits',
'm_field_label' => 'Credits',
'm_field_type' => 'text'
));
}