Customizing SMF > SMF Coding Discussion

updateMemberData

(1/2) > >>

The Wizard:
Hello:

I'm using SMF 2.0.2 and will all the changes so I'm unclear on exactly what to use.

Below is my code that will add the name of a image "rose" to the table shop_wizard. 


--- Code: ---function onUse()
{
global $user_info;

updateMemberData($user_info['id'], array('shop_wizard' => 'roses'));

return '<br>You now own 12 long-stem roses.<br /><br />We here at Acme Florists division hopes that they will brighten your day.<br />
<br />Enjoy<br />
<br />Acme Division Products Company<br /><br />';
}
--- End code ---

I would like to add a series of images to this table - example - roses, rock, cat, dog
How would I go about adding this information to the table without wrighting over the images names already in the file. Just to make this clear - I want to add one image name per function.

Thanks

Wiz

The Wizard:

--- Code: ---global $user_info;

updateMemberData($user_info['id'], array('shop_wizard' => 'roses'));
--- End code ---

I know the code above will add "roses" to shop_wizard. What I would like to know is if it will over wright any data existing in shop_wizard or will it just add "roses" to any other data in shop_wizard? I can't seem to find much information about how or what exactly updateMemberData does. The SMF Online manual is useless here.

Wiz

Sorck:
Assuming the shop_wizard column exists in {db_prefix}members then it will bascially run:

--- Code: ---$smcFunc['db_query']('', 'UPDATE {db_prefix}members
SET shop_wizard = roses
WHERE id_member = {int:id_member}', array(
'id_member' => $user_info['id']
));
--- End code ---

Therefore it replaces that columns value.


EDIT: It will do the same for any columns. For example it would replace the value of the e-mail address, karma etc.

The Wizard:
OK then how do I add to shop_wizard? Say I have "roses" in shop_wizard and a few days later I want to add "rock" to shop_wizard without out erasing the data already in shop_wizard which is "roses"?

ziycon:
Due to the way the updateMemberData() function works you would need to add the values comma exasperated. This is because the array expects the column name(shop_wizard) and the value for that column(roses).

So what you could do is retrieve the value from the shop_wizard for the member in question check if its empty, if not, add the new value into it.

Get 'shop_wizard' value for user X
If 'shop_wizard' is not empty
   update member: shop_wizard value+new value
else
   update member: new value

I hope this makes sense.

Navigation

[0] Message Index

[#] Next page

Go to full version