Joomla! 3.10
CB 2.6.2
PHP 7.4.16
MySQL 5.7.32
I have a number of club members who can 'mentor' other members on a number of topics. Each 'mentor' may cover various topics, and each topic may have many mentors available..
When an ordinary club member registers for support I wish to email only those 'mentors' that can cover that topic. I can set up an auto action of type email, but wish to be able to derive the comma separated list of mentor email addresses for that topic for use in the CC field of the email..
I have tried using a CB Code type field with variations of the following code:
_____________________________________________________
// Prepare an empty array
$items = array();
// Prepare the database connection
$db = JFactory::getDbo();
// Run the SQL query and store it in $results
$db->setQuery("SELECT mentor_email FROM confreretestdb.diploma_mentor_subject");
$results = $db->loadObjectList();
// Now, load the array.
foreach ($results as $result) {
$email = $result->mentor_email;
$items[] = $email;
}
// Multiple values are to be separated by commas,
$items = implode(",", $items);
// Now return the value
return $items;
________________________________________________________________
However, this always results in an error (syntax error, unexpected end of file) or occasionally a fixed value of "Array".
I am not a programmer (the above code is copied from elsewhere), so is this the right way of creating my list, or is there a better way. If the above is a suitable method, can you advise where I am going wrong.