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

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Tue Jul 26, 2011 10:36 pm

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
Last edited by admin12 on Thu Jul 28, 2011 1:28 am, edited 1 time in total.

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

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

Post by dglass » Tue Jul 26, 2011 11:19 pm

Did you declare the global in the other cards?

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Wed Jul 27, 2011 1:09 am

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

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

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

Post by dglass » Wed Jul 27, 2011 4:06 am

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.

karmacomposer
Posts: 361
Joined: Wed Apr 27, 2011 2:12 pm

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

Post by karmacomposer » Wed Jul 27, 2011 5:42 pm

OK. I declared it everywhere.

Global curUserID

So, in this line:

put "the new value" into theGlobalVariable

is curUserID the theGlobalVariable?

Mike

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

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

Post by dglass » Wed Jul 27, 2011 5:49 pm

Yes.

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Wed Jul 27, 2011 6:26 pm

Got it - I think it's working. I'll have to test it by making a bunch of records.

Mike

SparkOut
Posts: 2949
Joined: Sun Sep 23, 2007 4:58 pm

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

Post by SparkOut » Wed Jul 27, 2011 7:59 pm

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)

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

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

Post by admin12 » Wed Jul 27, 2011 9:56 pm

Thank you.

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

Mike

Post Reply