繁体   English   中英

为什么此代码块会导致空白?

[英]Why does this block of code result in a blank space?

我的目标是减去两次,然后从那里生成一个已登录的检查器。

我需要知道的是,是否在几分钟内正确地减去了两次。

PHP版本:7.0

使用NOW()将时间输入到数据库中,并显示为(例如:2016-07-23 15:01:34)

出于某种原因,此代码包含在HTML中,只是空白。

代码(所有内容都在代码的上方定义):

<?php

include ('../includes/connection.php');
include ('../scripts/functions.php');

$getOnlineAdmins = $handler->prepare('SELECT * FROM Admins WHERE AdminLevel >= :al AND Status= :stat');
$statn = 1;
$aln = 1;
$getOnlineAdmins->bindParam(':al', $aln);
$getOnlineAdmins->bindParam(':stat', $statn);
$getOnlineAdmins->execute();

echo "
  <table class='table-fill'>
    <thead>
      <tr>
        <th class='text-left' style='padding-left: 12px; padding-right: 12px;';></th>
      </tr>
    </thead>
    <tbody class='table-hover'>";

if ($getOnlineAdmins->rowCount() >=1){
    echo ("These is one or more rows.");
    while ($results = $getOnlineAdmins->fetch()){
        if((strtotime($results['LastVisited']) + 900) >= time()){
            echo ("Time requirement met.");
            switch ($results['AdminLevel']) {
                case 3:
                    $rank = 'In-Training/Intern';
                    break;
                case 6:
                    $rank = 'Community Moderator';
                    break;
                case 9:
                    $rank = 'Senior Moderator';
                    break;
                case 12:
                    $rank = 'Supervisor';
                    break;
                case 15:
                    $rank = 'Administrator';
                    break;
                case 18:
                    $rank = 'Senior Administrator';
                    break;
                case 21:
                    $rank = 'Staff Advisor';
                    break;
                case 24:
                    $rank = 'Engineer';
                    break;
                case 27:
                    $rank = 'Vice Chairman';
                    break;
                case 30:
                    $rank = 'Chairman';
                    break;
                case 33:
                    $rank = 'Website Engineer';
                    break;
                default:
                    $rank = 'Unknown';
                    break;
            }
                echo "<tr>";
                echo "<td>" . $results['Username'] . " - " . $rank . "</td>";
            } else {
            echo "<tr><td>{$results['Username']} &ndash; $rank</td>";
        }
    }
}else{
    echo "<tr><td>There are no staff members online.</td>";
}
echo " </tbody>
      </table>";

?>

据我了解, now()无法获得您期望的当前时间。 我认为这是您误解的根源,请参阅问题。

假设$results['LastVisited']的格式为2016-07-23 14:11:02 –您可以使用strtotime将其转换为UNIX时间戳。

因此,如果15分钟前的时间小于或等于您上次访问的时间:

if (strtotime('-15 minutes') <= strtotime($results['LastVisited'])) {}

使用time()替代格式–您将使用它代替MySQL等效的UNIX_TIMESTAMP()

if ((time() - 900) <= strtotime($results['LastVisited'])) {}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM