aQ Posted May 19, 2007 Share Posted May 19, 2007 Hello again! I am trying to take calculate a variable - a variable. My variables are: $time and $lastclaim my calculation is: $turn = $time - $lastclaim; and then I print the "$turn". print $turn. This does not print anything... What is wrong? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/ Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 show the code that is used to print the $turn also what does var_dump($turn); display ? Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/#findComment-257012 Share on other sites More sharing options...
aQ Posted May 19, 2007 Author Share Posted May 19, 2007 float(993) is returned by var_dump($newturns); My code is: $nowtime = date("YmdHis"); $qlastclaim = mysql_query("SELECT lastclaim FROM users WHERE uname = '$uname'"); $lastclaim = mysql_fetch_row($qlastclaim); $newturns = $nowtime - $lastclaim[0]; mysql_query("UPDATE users SET turns = '$newturns', lastclaim = '$nowtime' WHERE uname = '$uname' LIMIT 1"); I get the time the user last time claimed "turns" and I want the "nowtime" to be taken away from "lastclaim" to calculate how many turns the user will get. Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/#findComment-257017 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 Personally i dont see a problem, if you echo $newturns after setting it, it should work, but as you stated $newturn in the first post i think you should double check, also echoing the SQL statement and and adding some error handleing m ay help $SQLq= "UPDATE users SET turns = '$newturns', lastclaim = '$nowtime' WHERE uname = '$uname' LIMIT 1"; echo $SQLq; mysql_query($SQLq)or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/#findComment-257025 Share on other sites More sharing options...
Lumio Posted May 19, 2007 Share Posted May 19, 2007 Hi! You try something that won't work. Use time() to get the seconds that ran since 1970. So! <?php $nowtime = time(); $qlastclaim = mysql_query("SELECT lastclaim FROM users WHERE uname = '$uname' LIMIT 1;"); //I also changed this line $row = mysql_fetch_assoc($qlastclaim); //and also changed this line $newturns = $nowtime - intval($row['lastclaim']); //I use intval to make an integer mysql_query("UPDATE users SET turns = '$newturns', lastclaim = '$nowtime' WHERE uname = '$uname' LIMIT 1"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/#findComment-257028 Share on other sites More sharing options...
aQ Posted May 19, 2007 Author Share Posted May 19, 2007 It works now... The reason it didn't work was that I calculated the "turns" before the username was read by PHP. I just needed to re-organize the code a little bit. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/#findComment-257030 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 welcome.. no idea what Lumio was chatting about but he does that :-\ Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/#findComment-257033 Share on other sites More sharing options...
Lumio Posted May 19, 2007 Share Posted May 19, 2007 -.- Man you suck @ MadTechie If you want to help... do it, but don't try to blame others who try to help. Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/#findComment-257037 Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 whatever dude.. Quote Link to comment https://forums.phpfreaks.com/topic/52120-solved-variable-variable/#findComment-257041 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.