警报间隔时间jquery mysql php

时间:2013-08-02 18:58:15

标签: php jquery mysql

抱歉,但有人有实时提醒的示例,例如

如果代理人在午餐时间过了10分钟就会发出警报并且时间依赖于数据库中的插入并插入表格中

非常有用,谢谢

我真正想要做的是如果比较它来制作不同的警报,但我不知道该怎么做..这不行吗

alert.php:

<?php
$host = "" ;
$user = "" ;
$pw = "" ;
$db = "operator" ;

$fechaactual = Date("Y-m-d H:i:s");

$con = mysql_connect($host,$user,$pw) or die ("problemas al conectar");
$database=mysql_select_db($db,$con) or die ("problemas al conectar la bd");

$re = mysql_query(" SELECT * FROM operator ");
while($m=mysql_fetch_array($re)){
$ahi = (strtotime($m['tiempo']));
$ahi1 = date("Y-m-d", strtotime("+10 minutes", $ahi));
$ingresada = strtotime($ahi1);
$now = strtotime($fechaactual);
$lsk = mysql_query("SELECT * FROM lates WHERE id_op ='".$m['ID']."'");   
if($ingresada > $now){
if(mysql_num_rows($lsk) == 0) {
echo "<script>";
echo "alert('".$m['nombre']."  over pass the  ".$m['status']."');";
echo "</script>";
mysql_query("INSERT INTO lates (id_op,nombre) VALUES     ('".$m['ID']."','".$m['nombre']."')");
}else {
echo "is already inserted";}
}
}
?>

这是脚本:

<div id="alertas">
<?php include("alertas.php"); ?>
</div>
<script>
function conn() {
    $("#alertas").load("alertas.php");
}
setInterval("conn()", 100);
</script>

我的桌子操作员......

CREATE TABLE `operator` (
`nombre` varchar(30) NOT NULL,
 `status` enum('available','break1','break2','lunch','out') character set swe7 NOT NULL   default 'available',
`tiempo` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`msj` varchar(30) default NULL,
`ID` int(15) unsigned NOT NULL auto_increment,
PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

和我的桌子说:

   CREATE TABLE `lates` (
  `id` int(50) NOT NULL auto_increment,
  `id_op` int(20) NOT NULL,
   PRIMARY KEY  (`id`)
   ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

1 个答案:

答案 0 :(得分:-1)

alert.php的PHP:

if ($something_your_alert == true) {
    $return['status'] = true;
} else {
    $return['status'] = false;
}
echo json_encode($return);

添加Ajax处理的<script type="text/javascript"></script>标记:

$.ajax({
  url: "/alert.php",
  type: "POST",
  data: parameters,
  success: function(data){
     // action of success, append to div
     if (data.status)
     {
         $("#divres").append("okay");
     }
     else
     {
         $("#divres").append("failed");
     }
     }
  },
  error: function(){
     $("#divres").append("failed");
  }
});

并输入div的<body>标记:

<div id="divres"></div>