Jump to content

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?????
thanks
Link to comment
https://forums.phpfreaks.com/topic/10027-global-variable-help/
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;
$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
Link to comment
https://forums.phpfreaks.com/topic/10027-global-variable-help/#findComment-37244
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.