Custom Profile Fields value SSI call

Started by larry1123, June 27, 2012, 01:53:53 AM

Previous topic - Next topic

larry1123

I need to be able to call the value the user set in a Custom Profile Field so that I can use it out of the forum. I will need the call to be able to pull only one Field because said field will not be viewed on the forums by other users, so permissions will have to be passed and I only want this one Field to be read from out side the forum.

I would hope that it would be able to be used something like this.

string ssi_custom_profile_field($memberID, $field_name)

The string it returns would be the set value of the field.
The two prams are in case I need to and more fields that need to be called form SSI. Use of these are not needed but would be nice to start with)

If some one does not fell like writing code for me I would be vary happy just to know where this data is stored in the DB. I Have looked and can not find the data for each user I can find the DB with Custom Profile Fields settings 'smf_custom_fields' but not the stored data.

Arantor

Take a look in the smf_themes table, for id_member = the member whose fields you want, and where variable items begin with 'cust_', e.g. a field called 'My Custom Field' will be in the database in cust_mycustom (IIRC it takes the first 8 non-space characters) and that's where you'll find the data.
Holder of controversial views, all of which my own.


larry1123

Ok so I found it but the field I am looking for was not the one made by the Facebook mod was there but not the one I made. Would there be anywhere else or does it only save it to the DB if the value is different than the default value?

Arantor

If it's a custom field set up by the custom fields in the admin panel, it will be in smf_themes, you just might have to search for it (but it'll definitely have cust_ as the prefix in the variable column)

I can't remember if it saves it regardless or whether it only saves it if it's non-default though.
Holder of controversial views, all of which my own.


larry1123

Yea I just changed it from default and now it is there.
Ok so this should be fun to make the code lol goes off to find out how to call the DB.

Arantor

You've loaded SSI.php, so...


$query = $smcFunc['db_query']('', '
  SELECT value
  FROM {db_prefix}themes
  WHERE id_member = {int:member}
    AND variable = {string:variable}',
  array(
    'member' => $memberID,
    'variable' => 'cust_myfieldidgoeshere',
  )
);

if ($smcFunc['db_num_rows']($request) == 0)
{
  $field_value = 0; // or whatever the default should be
}
else
{
  list($field_value) = $smcFunc['db_fetch_row']($request);
}

$smcFunc['db_free_result']($request);
Holder of controversial views, all of which my own.


larry1123

#6
If that was put in to a function what needs to be global?


Update I found out what needed to be Global, but this is what I get from using this
Resource id #60

I can see that the value in the DB is Forum.larry1123.net

Arantor

$smcFunc needs to be pulled from global as it's the only variable actually mentioned ;)
Holder of controversial views, all of which my own.


larry1123

 ;) as I was editing my post I saw that you posted lol

Update I found out what needed to be Global, but this is what I get from using this
Resource id #60

I can see that the value in the DB is Forum.larry1123.net

Arantor

I'll say it again: the only thing that needs to be global is $smcFunc. It's the only variable that code requires.

You're not supposed to return $request, you're supposed to return $field_value. I'm sorry I didn't make that obvious enough, but I figured if you knew enough to be putting this in a function, you'd know what to return from it.

$request only contains a resource, a link to the actual query's results, not the results themselves. Hence we use db_fetch_row to get the results and put them into $field_value for actual use.
Holder of controversial views, all of which my own.


larry1123

Quote from: larry1123 on June 27, 2012, 06:48:19 PM
Ok so this should be fun to make the code lol goes off to find out how to call the DB.

I have done nothing with the DB stuff my self before. I am still learning both PHP and how SMF works. Needless to say I have not gone over any SQL stuff yet.

But thank you for your help. Would you mind if I would try my hand at making a mod to do this using your code?

Arantor

Holder of controversial views, all of which my own.


Advertisement: