Many people don't realize that Moodle generates ID's for every student on the site. Unfortunately there is built-in way to show students their ID. The easiest way to show students their student ID in Moodle without any programming is to use a 3rd party Moodle plugin called Configurable Reports. It is usually used to generate reports in Moodle but can easily be adapted to just provide students with their ID.

Here is an example of how you would go about using this plugin.

  1. Install the Configurable reports plugin.
  2. Login as a site administrator.
  3. Go to the Front Page and turn on Editing.
  4. Add the Configurable Reports block to the page.
  5. Click Manage Reports.
  6. Click the Add Report button.
  7. For the name, enter "Show my student ID" or something like that. This text will be displayed to students on the Front Page as a link.
  8. Set Type of report to SQL Report and click the Add button.
  9. In the SQL Query field, add the following code and click the Save Changes button:
SELECT RIGHT(CONCAT('00000',id),6) AS "Student ID", username, firstname, lastname FROM prefix_user WHERE id = %%USERID%%

That's it, you're done.

Now go back to the Home page. You should see a link called "Show my student ID". When a student clicks on the link, it will show them a small report displaying their student ID prefixed with up to 6 zeros along with their username, first name and last name.

You can also use this SQL Query with the Adhoc Database Queries plugin but you might have to give students the report/customsql:view capability.

Bonus Tip: If you leave off the "WHERE id = %%USERID%%" part, the above SQL can also be used to generate an administrative report listing the student ID, username, first and last name for all students. If you add the phone1 and phone2 or email fields to the list, it can even be used as a student directory.