我对此束手无策,因为我真的需要继续前进,而我却被如此简单的任务所困!任何帮助将不胜感激。
我要做的是在倒计时达到 0 时回显 Times Up 消息。
我知道插件有一个 onExpiry 函数,但我不想使用 javascript。我想使用 PHP,所以用户不能禁用它。
这是我的完整代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php date_default_timezone_set('GMT'); ?>
<?php
session_start();
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "config/connect.php";
$dynamicList = "";
$sql = "SELECT * FROM item ORDER BY id ";
$query = mysqli_query($db_conx, $sql);
$productCount = mysqli_num_rows($query); // count the output amount
if ($productCount > 0) {
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$id = $row["id"];
$product_name = $row["product_name"];
$date_added = date("Y, m, d", strtotime($row["date_added"]));
$end_date = date("Y, m, j, G, i, s", strtotime($row["end_date"]));
$price = $row["price"];
$dynamicList .= '<div>' . $end_date . '
</div>';
}
} else {
$dynamicList = "No Records";
}
?>
<?php
$tmp_date = explode(', ', $end_date);
$tmp_date[1] = $tmp_date[1] - 1;
$end_date = implode(', ', $tmp_date);
?>
<?php
$date = $end_date;
$exp_date = date("Y, m, j, G, i, s", strtotime($date));
$now = time();
if ($now < $exp_date ) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<noscript>
<h3>JavaScript is disabled!
Please enable JavaScript in your web browser!</h3>
<style type="text/css">
#defaultCountdown { display:none; }
</style>
</noscript>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>jQuery Countdown</title>
<link rel="stylesheet" href="jquery.countdown.css">
<style type="text/css">
#defaultCountdown { width: 240px; height: 45px; }
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery.countdown.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#defaultCountdown').countdown({
until: new Date(<?php echo $end_date ?>),
compact: true,
onTick: warnUser
});
});
</script>
</head>
<body>
<?php
} else {
echo "Times Up";
}
?>
<div id="defaultCountdown" style="font-family:Verdana, Geneva, sans-serif;"></div>
<?php
} else {
echo "Times Up";
}
?>
</body>
</html>
目前我正在使用上面的代码,但我得到的只是(Times Up)消息,页面上没有任何其他内容,这是计时器有几个小时结束但当我删除这些行时:
<?php
$date = $end_date;
$exp_date = date("Y, m, j, G, i, s", strtotime($date));
$now = time();
if ($now < $exp_date ) {
?>
和
<?php
} else {
echo "Times Up";
}
?>
计时器出现并再次开始工作。一旦计数器达到 0,我需要找到一种方法来显示/显示 Times Up 消息,出于安全原因,我需要通过 PHP 来完成。
提前致谢。