asmith Posted December 1, 2007 Share Posted December 1, 2007 $a = date('Y-m-d.H-i-s'); how can i store the result into a string ? for example : echo $a; //do a lot of stuff now if i again echo $a . this will output new time, what i want is the first time $a echoed value , or the first time php put date function value in $a hard for me to explain , i hope you get what i mean . i want to make date function value in a string that would be safe and fixed, so every time i echo the string i would have a fixed string, not an up-tp-date changble date. (please note i don't want to store the date in mysql , the get it back from it ,i want to do it all in php) Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 1, 2007 Share Posted December 1, 2007 $a can only be updated by: $a = date('Y-m-d.H-i-s'); therefore, your script must be running this line multiple times. If it's only run once, $a will only contain one value. You will need to post more code for us to help you with some logic that will retain one value. PhREEEk Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 1, 2007 Share Posted December 1, 2007 create some session variables and store the $a variable in one of those sessions. then check to see if the season has been set; if it has, then set $a to something other then a date and if the season has not been set, let variable $a remain as a date value. try something like this: <?php start_session(); if (isset($_SESSION["lockeDate"] == "yes")) { $a = $_SESSION["lockenDate"]; } else { $a = date('Y-m-d.H-i-s'); $_SESSION["lockenDate"] == $a; $_SESSION["lockeDate"] == "yes"; } ?> Quote Link to comment Share on other sites More sharing options...
asmith Posted December 1, 2007 Author Share Posted December 1, 2007 both good answers, $a can only be updated by: $a = date('Y-m-d.H-i-s'); therefore, your script must be running this line multiple times. If it's only run once, $a will only contain one value. You will need to post more code for us to help you with some logic that will retain one value. PhREEEk so the out put of this : $a = date('Y-m-d.H-i-s'); //do a lot stuff that takes 5 minutes echo $a the output of a$ is the 5 minutes earlier ? create some session variables and store the $a variable in one of those sessions. then check to see if the season has been set; if it has, then set $a to something other then a date and if the season has not been set, let variable $a remain as a date value. yea, session looks will work fine . Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 1, 2007 Share Posted December 1, 2007 As long as $a is not re-defined, then yes, it retains the value from the first definition. PhREEEk Quote Link to comment Share on other sites More sharing options...
jumpfroggy Posted December 1, 2007 Share Posted December 1, 2007 so the out put of this : $a = date('Y-m-d.H-i-s'); //do a lot stuff that takes 5 minutes echo $a the output of a$ is the 5 minutes earlier ? Yes, if you set $a to the date, then it'll be that date till the end of the page or $a is reassigned. $a = date(...); // $a is now "2007-12-01.01-59-01" // Do stuff that takes 2 days print $a; // will print "2007-12-01.01-59-01" Quote Link to comment Share on other sites More sharing options...
asmith Posted December 1, 2007 Author Share Posted December 1, 2007 yep ! solved ! but i think i'm completely mixed up !!! each user run the script for hisself , right ? if 3 users run this script the same time ... ahh stupid question ! i'm just mixed up ! lol Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 1, 2007 Share Posted December 1, 2007 I kind screwed-up on my script there a little bit asmith - sorry about that - I didn't test it before I posted it. here's what it should have been: <?php session_start(); $a = date("Y-m-d.H-i-s"); if ($_SESSION['lockeDate'] == 'yes') { $a = $_SESSION['lockenDate']; } else { $_SESSION['lockenDate'] = $a; $_SESSION['lockeDate'] = yes; } ?> Quote Link to comment 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.