Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按值增加字段_Php_Mysql_Pdo - Fatal编程技术网

Php 按值增加字段

Php 按值增加字段,php,mysql,pdo,Php,Mysql,Pdo,首先,我的代码: $LogOut = $DB->prepare("UPDATE users SET online = '0', last_online = '$time', times_logged_in = times_logged_in + 1, time_spent_online = time_spent_online + $TimeSpent WHERE id = '$sessid'"); 我的问题是上一次更新“在线花费的时间=在线花费的时间+$timespunt”我应该如何格式

首先,我的代码:

$LogOut = $DB->prepare("UPDATE users SET online = '0', last_online = '$time', times_logged_in = times_logged_in + 1, time_spent_online = time_spent_online + $TimeSpent WHERE id = '$sessid'");

我的问题是上一次更新“在线花费的时间=在线花费的时间+$timespunt”我应该如何格式化它?我不能简单地写数字,因为数字根据用户在线的时间而变化。

增加分钟怎么样

time_spent_online = time_spent_online + interval $TimeSpent minute

你不应该有一个a字段
在线花费的时间
。相反,您应该随时计算请求的时间(当然,在需要时缓存结果)

在另一个表中,您需要记录用户每次登录的时间。从这个表中,您可以简单地计算在线花费时间的估计值