l3fthand Posted May 19, 2006 Share Posted May 19, 2006 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?????thanks Quote Link to comment https://forums.phpfreaks.com/topic/10027-global-variable-help/ Share on other sites More sharing options...
kenrbnsn Posted May 19, 2006 Share Posted May 19, 2006 Why is using a MySQL database not an option?Can you post the code you are currently using?Ken Quote Link to comment https://forums.phpfreaks.com/topic/10027-global-variable-help/#findComment-37240 Share on other sites More sharing options...
l3fthand Posted May 19, 2006 Author Share Posted May 19, 2006 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; $str="Question"; $question->name=$str . $globalVar; $globalVar=$globalVar+1;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 Quote Link to comment https://forums.phpfreaks.com/topic/10027-global-variable-help/#findComment-37244 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.