Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: The Wizard - helmikuu 10, 2014, 04:32:32 IP

Otsikko: function issue / question
Kirjoitti: The Wizard - helmikuu 10, 2014, 04:32:32 IP
Hello:

The script below works fine when I call it in another function.
I am using ToyShopLinks_Credit_Center(); to call the function.

Now here is the weird part - when I call the function a second time I get the exact same result - even though the money count has changed.
I am guessing that somehow it's not reading again or some variable is not reset.

Anybody have a idea how to fix this?

Wiz




function ToyShopLinks_Credit_Center()
{
global $context, $smcFunc, $txt;

loadTemplate('ToyShopUser');
loadLanguage('toy shop languages/ToyShop', 'english');

$pocket = 0;
$atm = 0;

$result = $smcFunc['db_query']('', "
SELECT money, moneyBank
FROM {db_prefix}members
WHERE id_member = {int:id}
LIMIT 1", array(
'id' => $context['user']['id']
));
$row = $smcFunc['db_fetch_assoc']($result);
$smcFunc['db_free_result']($result);

$pocket = formatMoney($row['money']);
$atm = formatMoney($row['moneyBank']);

$context['toy_shop_credit_center'] = sprintf($txt['toy_shop_currently_have1'], $pocket, $atm);
}
Otsikko: Re: function issue / question
Kirjoitti: codenaught - helmikuu 10, 2014, 06:44:25 IP
At what stage are you expecting it to yield a different result the second time you run it?

I am seeing a query into a database for some data, but I don't see anywhere that is updating anything in the database?
Otsikko: Re: function issue / question
Kirjoitti: The Wizard - helmikuu 10, 2014, 06:53:59 IP
Hello:

if you want to see the entire code go here
http://www.simplemachines.org/community/index.php?topic=517744.msg3668099#new
and download the latest version.

I was hoping to see if I missed anything simple. I tend to miss the really obvious stuff.

Thanks

Wiz
Otsikko: Re: function issue / question
Kirjoitti: margarett - helmikuu 10, 2014, 08:12:48 IP
As far as  I see it, you call that function in pretty much every function. Kind of an initialization, right?

I don't see why you expect different values, unless a user had changed values between page loads. In each page load that function should be called only once so...
Check the database values via phpmyadmin and compare them to the returned values.

If you want to be sure, try to echo/print_r some values while it is being processed.
Otsikko: Re: function issue / question
Kirjoitti: The Wizard - helmikuu 14, 2014, 10:02:41 AP
Hello:

I finally solved this issue - it turned out is was a catching issue on the browser side, and so the results were messed up.

Thank you I really appreciate all the help and support. I don't think I would have gotten as far as I have without you and everybody else who has helped me. Again Thank you everybody.

Wiz