News:

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

Main Menu

updateMemberData usage question

Started by eresaru, December 15, 2020, 04:38:48 AM

Previous topic - Next topic

eresaru

Hi everyone,
I am not even sure this is the proper thread to ask, please mods, feel free to move accordingly.

I am writing a very quick and small mod for my forum and I am running into the following issue. I want to increase the count of a column for a specific user by 1. As per the documentation I am doing:
updateMemberData($row['id_member'],array('count_something'=>'+'));

However, I am getting the following error in the logs (and the value is not increased):
A non-numeric value encountered

What am I doing wrong?

SychO

This column is a new one you have added right ?

Assuming so, the new column you've added is not a known int as far as the code is concerned.

The updateMemberData function which you can find in Subs.php has a defined array of column names that are of integer type, the + and - will only work on these columns.


$knownInts = array(
'date_registered', 'posts', 'id_group', 'last_login', 'instant_messages', 'unread_messages',
'new_pm', 'pm_prefs', 'gender', 'show_online', 'pm_receive_from', 'alerts',
'id_theme', 'is_activated', 'id_msg_last_visit', 'id_post_group', 'total_time_logged_in', 'warning',
);


Some things you can do:

1. Manually increase the value:

updateMemberData($row['id_member'], array('count_something' => $value+1));


2. Use a direct database query to increment the value

$query = $smcFunc['db_query']('',
UPDATE {db_prefix}members
SET count_something = count_something + 1
WHERE id_member = {int:member_id}',
array(
'member_id' => (int) $member_id,
)
);


3. Use the hook integrate_change_member_data to add your column name to the array of $knownInts.

function add_count_something_to_known_ints($member_names, $var, $data[$var], &$knownInts)
{
if (!in_array('count_something', $knownInts))
{
$knownInts[] = 'count_something';
}
}
Checkout My Themes:
-

Potato  •  Ackerman  •  SunRise  •  NightBreeze

eresaru

Thank you so very much.
It makes perfect sense now.

Advertisement: