Jump to content

[SOLVED] variable - variable


aQ

Recommended Posts

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.

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());

 

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");
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.