Page 1 of 1

SOLVED - How can I make a variable useable from card to card

Posted: Tue Jul 26, 2011 10:36 pm
by admin12
In the Opencard handler of the login card, I made a variable global (ie. global CurUserID). Login now works fine and I am reading from the database perfectly.

I expected that variable to be useable across other cards, but it was not.

I am looking up a User's ID from the UserValidation table (which I have checked on, and it is reading it properly) and I want that UserID to then carry over to other cards . . . or should I be using $_SESSION instead?

That way I can track the logged in user via his or her UserID.

How is this done?

Mike

Re: How can I make a variable useable from card to card

Posted: Tue Jul 26, 2011 11:19 pm
by dglass
Did you declare the global in the other cards?

Re: How can I make a variable useable from card to card

Posted: Wed Jul 27, 2011 1:09 am
by admin12
I have it declared in the opencard of each card.

However, the LOGIN card's SUBMIT button is where the script is for determining the user info. Once I have the UserID, how do I put it in a global variable that can be used on every card in the stack?

Mike

Re: How can I make a variable useable from card to card

Posted: Wed Jul 27, 2011 4:06 am
by dglass
If you've declared the global in all the scripts you need to access it, then you should be able to do:

put "the new value" into theGlobalVariable

in the Submit button's script, and it will be available in all the places you've declared it.

AFAIK, globals don't inherit, so if you've declared it in the card, and you need it in a button on the card, you need to declare it in the button as well.

Re: How can I make a variable useable from card to card

Posted: Wed Jul 27, 2011 5:42 pm
by karmacomposer
OK. I declared it everywhere.

Global curUserID

So, in this line:

put "the new value" into theGlobalVariable

is curUserID the theGlobalVariable?

Mike

Re: How can I make a variable useable from card to card

Posted: Wed Jul 27, 2011 5:49 pm
by dglass
Yes.

Re: How can I make a variable useable from card to card

Posted: Wed Jul 27, 2011 6:26 pm
by admin12
Got it - I think it's working. I'll have to test it by making a bunch of records.

Mike

Re: How can I make a variable useable from card to card

Posted: Wed Jul 27, 2011 7:59 pm
by SparkOut
Just to be clear, a global needs to be defined in every script where it will be used (not in every handler).
So if you have the global defined at the top of the card script, you don't need to declare it inside all the handlers within the card script. If you need to use the global value in a button's script, define it at the top of the script and it will be available to all the handlers in that button script (eg mouseUp, mouseDown, mouseEnter, etc)

Re: How can I make a variable useable from card to card

Posted: Wed Jul 27, 2011 9:56 pm
by admin12
Thank you.

I have it at the top of each and every script. It seems to be working well.

Mike