Jump to content


This topic is now archived and is closed to further replies.


Global variable help

Recommended Posts

I need to have a counter in a file, but everytime the file is called the counter is reset to zero. Is there anyway I can keep the value?? Cookies and an SQL database are out of the question. But basically its a file with functions, right now i call teh global variable $globalVar in each function and add it to the end of a string so it results in "Question1", "Question2", etc.... But if I try to use this file again,File is used 2 or 3 times, $globalVar is reset to zero, and I get two Question1's and 2 question2's etc. but i would like $globalVar to start where it left off, when the file exited the time before, any suggestions?????

Share this post

Link to post
Share on other sites
Why is using a MySQL database not an option?

Can you post the code you are currently using?


Share this post

Link to post
Share on other sites
Well...I can't add a table to the database, because this is just one part of a much bigger project, and changing the database isn't an option. Basically, im importing questions for a test, importing just one file works fine. But when i go to import another, it will name the ?'s the same, although they still have their own id's in the database, but the name they show is the same. There is a file called import.php which calls format.php, and im working inside format.php. format.php formats the questions to work on the new system, then returns them back to import.php, then they are entered into the database. But i have tried declaring the global variable in both files, but as both are called new each time i try to import a new set of questions the value is reset.

this is the code im using to name the questions.....

global $globalvar;
$question->name=$str . $globalVar;

which works just fine. This is in like 5 different functions, each of which is a different question type, just need to know if the variable could stay unchanged the next time the same php file is called

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.