Jump to content

[SOLVED] variable - variable


aQ

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
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.