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.
- Install the Configurable reports plugin.
- Login as a site administrator.
- Go to the Front Page and turn on Editing.
- Add the Configurable Reports block to the page.
- Click Manage Reports.
- Click the Add Report button.
- 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.
- Set Type of report to SQL Report and click the Add button.
- 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.