drcb19700 2017-07-17 10:19
浏览 55
已采纳

24小时后价值不会改变

I find code on this forum and I go use it.

$sql2 = "SELECT TIME_TO_SEC(TIMEDIFF(NOW(), time)) FROM database WHERE id = 1";
$result = $conn->query($sql2);

if ($result >= 86400) { 
    $sql5 = "UPDATE points SET value = 1 WHERE id = 1"; 
    $result = $conn->query($sql5);
    $sql6 = "UPDATE points SET time = NOW() WHERE id = 1";
    $result = $conn->query($sql6);
}

Here is my code.

It doesn´t change after 24 hours.

SQL - time:

2017-07-16 11:10:06

It saves time.

And it doesn´t work.

So thank you guys for help.

I have this now:

    $sql2 = "SELECT TIME_TO_SEC(TIMEDIFF(NOW(), `dailytime`)) FROM `points` WHERE steamid = '".$steamprofile['steamid']."'";
    $result = $conn->query($sql2);

    if ($result >= 86400) { 
        $sql5 = "UPDATE points SET daily = 1 WHERE steamid = '".$steamprofile['steamid']."'"; 
        $result = $conn->query($sql5);

        $sql6 = "UPDATE points SET `dailytime` = NOW() WHERE steamid = '".$steamprofile['steamid']."'";
        $result = $conn->query($sql6);
    }
  • 写回答

1条回答 默认 最新

  • dsrjs86444 2017-07-17 10:48
    关注

    Oh silly us, we missed the obvious mistake.

    The result of a ->query() is a handle/object that allows you to process the results set generated by the query. It does not return the result set itself.

    Also with these queries, adding an alias name to the calculation makes getting at the column in the resultset easier.

    Assuming you are using mysqli_ you need to add some code to get your result set

    $sql2 = "SELECT TIME_TO_SEC(TIMEDIFF(NOW(), `dailytime`)) as the_diff 
            FROM `points` 
            WHERE steamid = '".$steamprofile['steamid']."'";
    
    $result = $conn->query($sql2);
    
    $row = $result->fetch_assoc();
    
    if ($row['the_diff'] >= 86400) { 
    
        // You can change more than one column in a single query
        // so you only need one UPDATE here
        $sql5 = "UPDATE points SET daily = 1, `dailytime` = NOW()
                 WHERE steamid = '{$steamprofile['steamid']}'"; 
        $result = $conn->query($sql5);
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程