News:

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

Main Menu

updateMemberData

Started by The Wizard, August 09, 2012, 01:07:29 PM

Previous topic - Next topic

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. 

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 />';
}


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

global $user_info;

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


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:
$smcFunc['db_query']('', 'UPDATE {db_prefix}members
SET shop_wizard = roses
WHERE id_member = {int:id_member}', array(
'id_member' => $user_info['id']
));


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.

The Wizard

#5
so something like this?

function onUse()
{
global $user_info;

A$ = $profile['shop_wizard'];

if empty($profile['shop_wizard'])
{
updateMemberData($user_info['id'], array('shop_wizard' => 'roses', A$));
} else {
updateMemberData($user_info['id'], array('shop_wizard' => 'roses'));

}
}

The Wizard

So if I had "roses" already in the shop_wizard and wanted to add "rock" would this code work? Assuming I had "shop_wizard" creaded which I do.


function onUse()
{
global $user_info;

A$ = $profile['shop_wizard'];

if empty($profile['shop_wizard'])
{
updateMemberData($user_info['id'], array('shop_wizard' => 'rock', A$));
} else {
updateMemberData($user_info['id'], array('shop_wizard' => 'rock'));

}
}

ziycon

At a brief glance the logic looks ok. You will need to make sure you wrap the if clause with round brackets.

The Wizard

When I use the code below I get the following error any ideas?

QuoteThe database value you're trying to insert does not exist: p_0

function onUse()
{
global $user_info;

$A = $profile['shop_wizard'];

if (empty($profile['shop_wizard']))
{
updateMemberData($user_info['id'], array('shop_wizard' => 'rock', $A));
} else {
updateMemberData($user_info['id'], array('shop_wizard' => 'rock'));

}
}
   

Advertisement: