jamesxg1 Posted April 10, 2009 Share Posted April 10, 2009 ok i set $_SESSION['time'] to time(); and this is what i need to work... <?php session_start(); $time = $_SESSION['time']; $timeout = 2; $new = "$time + $timeout"; if ($time = $new) { print "$time"; print "<br>"; print "$new"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/ Share on other sites More sharing options...
jamesxg1 Posted April 10, 2009 Author Share Posted April 10, 2009 it just prints + 2 + 2 Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806242 Share on other sites More sharing options...
Mark Baker Posted April 10, 2009 Share Posted April 10, 2009 Get out of the habit of quoting everything. If you want to add two numbers together use: $new = $time + $timeout; not $new = "$time + $timeout"; Also ensure that you are actually setting $_SESSION['time'] Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806243 Share on other sites More sharing options...
jamesxg1 Posted April 10, 2009 Author Share Posted April 10, 2009 ok now its printing 1239358810 + 2 1239358810 + 2 Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806244 Share on other sites More sharing options...
jamesxg1 Posted April 10, 2009 Author Share Posted April 10, 2009 Get out of the habit of quoting everything. If you want to add two numbers together use: $new = $time + $timeout; not $new = "$time + $timeout"; Also ensure that you are actually setting $_SESSION['time'] Damn my bad lol, sorry i was trying every way possible last night to get it working and must not of removed the quotes lol, and the $_SESSION['time']; var is set with the login time. 100#% working Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806245 Share on other sites More sharing options...
Mark Baker Posted April 10, 2009 Share Posted April 10, 2009 if ($time = $new) { will set the value of $time to the value of $new, and then execute the if logic if ($time == $new) { will compare the value of $time with the value of $new and only execute the if logic if the two values are equal Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806246 Share on other sites More sharing options...
jamesxg1 Posted April 10, 2009 Author Share Posted April 10, 2009 if ($time = $new) { will set the value of $time to the value of $new, and then execute the if logic if ($time == $new) { will compare the value of $time with the value of $new and only execute the if logic if the two values are equal correct, iv changed it and all i get now is 1239358810 1239358810 + 2 Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806252 Share on other sites More sharing options...
Mark Baker Posted April 10, 2009 Share Posted April 10, 2009 correct, iv changed it and all i get now is 1239358810 1239358810 + 2 Have you still got $new = "$time + $timeout"; because $time and $new shouldn't match, so the if condition shouldn't be met, so you should actually see nothing Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806255 Share on other sites More sharing options...
jamesxg1 Posted April 10, 2009 Author Share Posted April 10, 2009 <?php session_start(); $time = $_SESSION['time']; $timeout = 2; $new = "$time + $timeout"; if ($time == $new) { print "$time"; print "<br>"; print "$new"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806338 Share on other sites More sharing options...
jamesxg1 Posted April 10, 2009 Author Share Posted April 10, 2009 <?php session_start(); $time = $_SESSION['time']; $timeout = 2; $new = $time + $timeout; if ($time == $new) { print "$time"; print "<br>"; print "$new"; } ?> this is the code, but i cant get no results here Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806532 Share on other sites More sharing options...
Mark Baker Posted April 10, 2009 Share Posted April 10, 2009 this is the code, but i cant get no results here You won't see any results because you're only printing results if $time and $new are the same... but they're not going to be the same because $new is 2 more than $time if ($time == $new) { print $time.' and '.$new.' are the same'; } else { print $time.' and '.$new.' are not the same'; } Quote Link to comment https://forums.phpfreaks.com/topic/153458-php-maths-help/#findComment-806583 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.