Jump to content

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

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.