Customizing SMF > SMF Coding Discussion

Custom Profile Fields value SSI call

<< < (2/3) > >>

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


--- Code: ---$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);

--- End code ---

larry1123:
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 ;)

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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version