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.
March 7, 2019 at 2:39 AM
Thanks for sharing this post,
is very helpful article.
March 19, 2019 at 10:25 PM
You are welcome Facultell! Be sure to also checkout the FilterCodes plugin. It will let you insert the ID of a student as simply as typing {id} in a block, page or anywhere else that supports Moodle filters (probably about 90% of Moodle). You can download it from https://moodle.org/plugins/filter_filtercodes
May 26, 2019 at 6:17 PM
Salut pour vous, Thanks so much for sharing these awesome tips. They make a lot of sense and I know they work because I have tried some myself. Thanks for giving hope and guidance to teachers. I shared this link with others. Keep posting such information. Un sujet très intéressant, Merci.
July 7, 2022 at 6:33 PM
Thanks Michael,
Moodle generates ID’s for every student on the site and I followed your great instructions and can show the ID’s to the students with Configurable Reports (and/or filtercodes).
Any ideas or pointers of how it might be possible to make it that admin can see the Moodle generated student’s ID number in the student’s profile?
January 22, 2023 at 3:20 PM
Hi Suzanne,
The ID is available in the URL when you are on the Edit Profile page in your web browser. Just look for user/profile.php?id=37241. The id= shows the user ID of the profile being viewed. I know it is not exactly what you were hoping for. To get it to do exactly what you want would require some custom development.
Hope you find this helpful.
Best regards,
Michael