【发布时间】:2016-09-27 16:25:33
【问题描述】:
我这里有一个倒计时脚本
<h2 id="countdown"></h2>
<script>
var CountDownTimer;
CountDownTimer = function(dt, id) {
var _day, _hour, _minute, _second, end, selector, showRemaining, timer;
selector = document.getElementById(id);
end = new Date(dt);
_second = 1000;
_minute = _second * 60;
_hour = _minute * 60;
_day = _hour * 24;
showRemaining = function() {
var days, distance, hours, minutes, now, seconds;
now = new Date();
distance = end - now;
if (distance <= 0) {
CountDownTimer("09/27/2016 20:00", "countdown");
return;
}
days = Math.floor(distance / _day);
hours = Math.floor((distance % _day) / _hour);
minutes = Math.floor((distance % _hour) / _minute);
seconds = Math.floor((distance % _minute) / _second);
return selector.innerHTML = days + "days " + hours + "hrs " + minutes + "mins " + seconds + "secs";
};
return timer = setInterval(showRemaining, 1000);
};
CountDownTimer("09/27/2016 19:00", "countdown");
</script>
倒计时完成后,我希望查询从数据库中选择一个随机行并将倒计时重新开始到 +1 小时。 1 小时后,我希望这种情况再次发生。
这是应该选择随机行的代码,如果可能的话,这是我希望在倒计时脚本中执行的代码。
<?php $sql = "SELECT * FROM users ORDER BY RAND() LIMIT 1"; $result1 = $conn->query($sql);?>
这是最后一个代码的结果代码
<?php
if ($result1->num_rows > 0) {
// output data of each row
while($row = $result1->fetch_assoc()) {
echo $row["username"];
}
} ?>
此代码现在可以工作,但问题是每次我刷新页面时,都会选择一个新的随机行。我想要的是每小时选择一个新的随机行。
【问题讨论】:
标签: php mysql database countdown