News:

Wondering if this will always be free?  See why free is better.

Main Menu

Get value of custom profile field in profile

Started by mabley, September 19, 2024, 05:36:29 PM

Previous topic - Next topic

mabley

I'd like my users to be able to choose from a list of colors to accent their profiles, so I made a custom profile field.

In Profile.template.php how do I get the value of that custom profile field? I was thinking of using it as a CSS class or html data-attribute on the profile's wrapping div.

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

GL700Wing

Quote from: mabley on September 19, 2024, 05:36:29 PMI'd like my users to be able to choose from a list of colors to accent their profiles, so I made a custom profile field.

In Profile.template.php how do I get the value of that custom profile field? I was thinking of using it as a CSS class or html data-attribute on the profile's wrapping div.
Custom field definitions/values are stored in the {db_prefix}custom_fields table and if a member has saved a custom field it's name and value are stored in the {db_prefix}themes table.

Use the following query to get the value of the custom field named 'color' for an individual member (assumes member ID is available as $context['id_member']):
(Note: $profileColor will be empty/blank if the member has not saved the 'color' custom profile field)
$request = $smcFunc['db_query']('', '
SELECT value FROM {db_prefix}themes
WHERE id_theme = 1 AND id_member = {int:id_member} AND variable = {string:variable}',
array(
'id_member' => $context['id_member'],
'variable' => 'cust_color',
)
);
$profileColor = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);


The following is an example of a query to get the member ID and custom field value of all the members who have saved the custom field named 'color'.
$request = $smcFunc['db_query']('', '
SELECT id_member, value FROM {db_prefix}themes
WHERE id_theme = 1 AND variable = {string:variable} ',
array(
'variable' => 'cust_color',
)
);
$allMembers_profileColors = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);
Life doesn't have to be perfect to be wonderful ...

Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

mabley

Thank you for your help.

I added $smcFunc to the global variables for function template_summary() in Profile.template.php.

I added $profileColor down below in the HTML like ' . $profileColor . '

This prints just the word Array in the HTML.

How do I get the value to show up? The field is a select/dropdown if that matters.

EDIT: Figured it out. I did ' . $profileColor['value'] . '

Advertisement: