1)在发送给用户
的消息后,事件时间和服务器时间的脚本相等2)每2秒页面将刷新一次。
<?php
//header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
@include("include/db_connection.php");
//include("user_notification_list.php");
$page = $_SERVER['PHP_SELF'];
$sec = "2";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
<?php
$query= mysql_query("SELECT event_date FROM
tbl_notification_list where main_id =96");
$row= mysql_fetch_array($query);
$event_time= $row['event_date'].'</br>';
$server_time= date('m-d-y h:iA');
ob_flush();
flush();
ECHO $event_time;
ECHO $server_time;
$a= $event_time;// '04-07-14 09:14PM';
$b= $server_time; // '04-07-14 09:15PM';09:15PM';
if($a==$b)
{
echo 'Message send success fully.';
}else
{
echo'comming sonn event.';
}
echo'</br>';
?>
</body>
</html>
答案 0 :(得分:0)
为什么不在MySQL查询中这样做?
$query = mysql_query("SELECT event_date
FROM tbl_notification_list
WHERE main_id = 96 AND
event_date = NOW()");
if (mysql_num_rows($query) > 0)
{
echo 'Message send success fully.';
}
else
{
echo'comming sonn event.';
}
您甚至可以稍微更改它,以便查询和事件日期之间的时间有时间滞后以允许发送邮件:
$query = mysql_query("SELECT event_date
FROM tbl_notification_list
WHERE main_id = 96 AND
(TIMESTAMPDIFF(SECOND, event_date, NOW()) BETWEEN 0 AND 3)");
if (mysql_num_rows($query) > 0)
{
echo 'Message send success fully.';
}
else
{
echo'comming sonn event.';
}
以上将允许3秒的时间延迟。
答案 1 :(得分:0)
我会期待javascript选项每2秒刷新一次页面。
时间= setInterval的(函数(){location.reload();},2000);