gpt4 book ai didi

php - 如何将 MySQL DATEDIFF 查询的结果作为变量传递给 PHP 函数?

转载 作者:行者123 更新时间:2023-11-29 08:48:31 26 4
gpt4 key购买 nike

我试图获取表“users”中“last_visited”列中的日期/时间与特定用户的当前日期/时间之间的差异(以秒为单位)。我认为以下查询应该可以做到这一点:

$query ="SELECT unix_timestamp(NOW()) - unix_timestamp(last_visit) from users WHERE username='$user'";
$result=mysql_query($query) or die(mysql_error());

但是,我不确定如何从中获取结果作为变量,以便将其传递给 PHP 函数。有人可以帮忙解决这个问题吗?

最佳答案

返回带有名称的结果:

$query ="SELECT unix_timestamp(NOW()) - unix_timestamp(last_visit) AS time_diff from users WHERE username='$user'";
$result=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_assoc($result))
{
$diff= $row['time_diff']
}

关于php - 如何将 MySQL DATEDIFF 查询的结果作为变量传递给 PHP 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11926033/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com