doumao1519 2014-04-08 06:16
浏览 24
已采纳

如果在向用户发送消息后服务器时间和事件时间为“等于”

1) Script in event time and server time is equal after message send to user

2) Every 2 second page will be refresh.

<?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>
  • 写回答

2条回答 默认 最新

  • dongzeao5047 2014-04-08 06:23
    关注

    Why not do it at the MySQL query?

    $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.';
    }
    

    You could even change it slight so that the time between the query and the event date have time lag to allow the mail to be sent:

    $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.';
    }
    

    The above would allow a 3 seconds time lag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?