# I wan to retrieve the department name and role assigned

**URL:** <https://www.phphelp.com/t/i-wan-to-retrieve-the-department-name-and-role-assigned/35739>\
**Category:** Code Snippets\
**Created:** [September 29, 2023, 6:36am UTC](https://www.phphelp.com/t/i-wan-to-retrieve-the-department-name-and-role-assigned/35739 "2023-09-29T06:36:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Usama](https://www.phphelp.com/user_avatar/www.phphelp.com/usama/32/4252_2.png) [@Usama](https://www.phphelp.com/u/Usama)\
**Post date:** [September 29, 2023, 6:36am UTC](https://www.phphelp.com/t/i-wan-to-retrieve-the-department-name-and-role-assigned/35739/1 "2023-09-29T06:36:49Z")

</div>

```
protected static function SendEmailForActivation(
    \Admin $admin, string $activationLink, string $email)
{
    // Below variables are used in email template.
    $adminName = $admin->displayName();
    $activationUrl = $activationLink;
    $logo = \Registry::siteUrl('/dns_full_logo.png');

    /* send mail */
    ob_start();
    eval(\Registry::template('EmailAccountActivation'));
    $bodyHtml = ob_get_clean(); 

```

The template is sending the username in the email after retrieving it as “adminName”.  
Additionally, I need to retrieve the department name and assigned role from the database. Could you please provide guidance on the process to retrieve this information?

---

<div class="post-metadata">

**Author:** ![katsry](https://www.phphelp.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@katsry](https://www.phphelp.com/u/katsry)\
**Post date:** [September 30, 2023, 5:49pm UTC](https://www.phphelp.com/t/i-wan-to-retrieve-the-department-name-and-role-assigned/35739/2 "2023-09-30T17:49:01Z")

</div>

I’m assuming that your `\Admin` class (or some related class) interacts with a database where the department name and role assigned to an admin are stored.

For illustration purposes, I’ll use a hypothetical database structure. Your actual implementation might differ:

```auto
class Admin {

    private $id; // assuming each admin has a unique ID

    // ... other properties and methods ...

    public function getDepartment() {
        $db = // get database connection;
        $query = $db->prepare("SELECT department FROM admin_table WHERE id = ?");
        $query->bind_param("i", $this->id);
        $query->execute();
        $result = $query->get_result();
        $row = $result->fetch_assoc();
        return $row['department'] ?? null;
    }

    public function getRole() {
        $db = // get database connection;
        $query = $db->prepare("SELECT role FROM admin_table WHERE id = ?");
        $query->bind_param("i", $this->id);
        $query->execute();
        $result = $query->get_result();
        $row = $result->fetch_assoc();
        return $row['role'] ?? null;
    }
}

```

**Retrieve and Assign the Department and Role in Your Method**

In your `SendEmailForActivation` method, retrieve the department and role using the methods from the first step:

```auto
$department = $admin->getDepartment();
$role = $admin->getRole();

```

Remember that this is an assumption but gives you an idea of how to solve the problem.  
Good luck
