display custom field at edit.php from DB table user_info_field

display custom field at edit.php from DB table user_info_field

by Kyaw Htoo Thwin -
Number of replies: 2

Hi Everyone,

I just want to display the exact a few custom field from user_info_field DB table which I created through "user profile field" from the administration setting at the edit page. The problems is right now I am getting all the customize field from user_info_field table. I know the main code is at the edit.php under user folder but I need a little help on displaying a few custom filed and hide the rest. Thanks in advance for help.


Average of ratings: -
In reply to Kyaw Htoo Thwin

Re: display custom field at edit.php from DB table user_info_field

by Luis de Vasconcelos -

Your question is not very clear, but I seems that you want to retrieve just certain custom profile fields. Is that correct?

But where are you trying to display those custom profile fields? Are you trying to display them in a plugin, or do you just want to retrieve the data via SQL?

Anyway, try this if you want to retrieve the data via SQL:

SELECT
    mdl_user.id AS student_id,
    mdl_user.firstname + ' ' + mdl_user.lastname AS student_name,
    mdl_user_info_field.id AS profile_field_id,
    mdl_user_info_field.name AS profile_field_name,
    mdl_user_info_data.data AS profile_field_value
FROM mdl_user
INNER JOIN mdl_user_info_data ON mdl_user.id = mdl_user_info_data.userid
INNER JOIN mdl_user_info_field ON mdl_user_info_data.fieldid = mdl_user_info_field.id
WHERE (mdl_user.deleted = 0)
AND (mdl_user_info_field.id = 2)

That will give you something like:

student_id   student_name         profile_field_id    profile_field_name  profile_field_value
1231        Michelle Slabbert   2                   HR ID               127803
1232        Melisha Sampoda     2                   HR ID               132803
1233        Mark Clif Smit       2                   HR ID               118875

The key is that if you use mdl_user_info_field.id = 2 it will give you the data in the SECOND custom profile field for all active users. Whatever id you specify in mdl_user_info_field.id determines which custom profile field will be returned. If you want the third custom profile field change it to: mdl_user_info_field.id = 3, or 1 for the first custom profile field, etc.

Average of ratings: Useful (1)
In reply to Luis de Vasconcelos

Re: display custom field at edit.php from DB table user_info_field

by Kyaw Htoo Thwin -
Thank you for your kind reply. You answer is useful for me. However, I would like to do a user edit form and hide the some custom profile field. Currently, moodle user edit form is displaying all the field which has inside DB user_info_field and I want to display only some field at the edit form. Sorry for my first question is not very clear and I hope someone can guide me the way. Thanks in advance.