Welcome Guest, Not a member yet? Register   Sign In
GLOBAL variable
#1

[eluser]dannythebestguy[/eluser]
I needed some help to write the GLOBAL variable which I can use it in the application. I read in some post that it can be done through libraries and config file. Can somebody help me by showing how exactly it can be done.

Appreciated...
#2

[eluser]Derek Allard[/eluser]
What information does said variable hold? What is its context? In general, yeah, a config file is probably the easiest to use for something like this.
#3

[eluser]dannythebestguy[/eluser]
It is a sort of a counter. Everytime the function is executed the value changes to $x++. This value has to be then put to the view.
#4

[eluser]Derek Allard[/eluser]
If that counter is available to only 1 user, use a session. If that counter is available to all users, store that in a database field.
#5

[eluser]Derek Allard[/eluser]
Oh, and I see this is your first post - welcome to CodeIgniter dannythebestguy.
#6

[eluser]dannythebestguy[/eluser]
Thanx Derek,

The problem is cannot use Database... Used by many users... Best option a GLOBAL variable... Plz can u help...

Thnx
#7

[eluser]Derek Allard[/eluser]
Are you a PHP person Danny?

The problem with trying to use a variable is that they only exist for that user. In other words, if 2 people are on your site, and each increments the variable 5 times, they'll each see "5" and not "10". Your only real options for sharing data between users when that data needs to change is either (1) using a database; (2) saving your information to files.

File writing is considerably slower then database access, but depending on how busy your site is, it could still work.

CodeIgniter userguide for file helper
#8

[eluser]dannythebestguy[/eluser]
Hello Derek,

Oh yes.. I am a hardcore PHP guy... working as a consultant for a Bank...

And this is what I am looking for... for each user the value has to be 5 and not 10. So a user logs in runs the function for x number of times and prints that number... Nothing to do with how many other users are logged in... Means it is a counter per user.
#9

[eluser]Derek Allard[/eluser]
Well my advice doesn't change then.
Quote:If that counter is available to only 1 user, use a session.
#10

[eluser]dannythebestguy[/eluser]
OK.. but the problem is I will be using 6 variables which change as per a function which has a switch function inside. So I will have to create 6 sessions which again I think wont be a good idea.. But having 6 Global variable will solve the problem... Plz advice..

Thnx
Dinesh




Theme © iAndrew 2016 - Forum software by © MyBB