通知PHP

时间:2018-07-19 13:20:09

标签: php html ajax

我的应用出现问题。我有一些通知,当到期日期在一个月内要到期时,需要增加通知框。

加载代码,此代码检查日期是否临近。

<?php
$con = mysqli_connect("localhost","root","");
if(!$con){
    echo"Not connect to Server";
}
if(!mysqli_select_db($con,'newusers')){
    echo 'Database not select';
}
$dateToday = date("Y-m-d");


$datePlusYear = date('Y-m-d', strtotime("+1 year"));
$datePlus11Month = date('Y-m-d', strtotime("+11 months"));
$count = 0;
$countOcasional = 0;
$sql1 ="SELECT ID_colaborador, DataConsulta, DataNasc, DCO from colaboradores ";
$result1=mysqli_query($con,$sql1) or die("Query incorrecta: $sql1");

while($row1=mysqli_fetch_assoc($result1)){

    $dataConsulta = $row1["DataConsulta"];
    $dataNascimento =$row1["DataNasc"];
    $dataConsultaOcasional = $row1["DCO"];
    $dataLimite = $row1["DataLimite"];

    if($dataConsultaOcasional != "" && $dataConsultaOcasional != NULL  && $dataConsulta != "" && $dataConsulta != NULL  ){
        $DataConsulta_notificacao = date("Y-m-d", strtotime(date("Y-m-d", strtotime($dataConsulta)) . " -1 months"));
        //$DataConsulta_notificacao = date("Y-m-d", strtotime(date("Y-m-d", strtotime($dataNascimento)) ));
        $DataConsultaOcasional_notificacao = date("Y-m-d", strtotime(date("Y-m-d", strtotime($dataConsultaOcasional)) . " -1 months"));

        $diasquefaltam= (int)((strtotime($dataLimite) - strtotime($dateToday))/(60*60*24));
        $diasquefaltam1= (int)((strtotime($dataConsulta) - strtotime($dateToday))/(60*60*24));
        if( ($diasquefaltam<=30 && $diasquefaltam>=0) &&($diasquefaltam1<=30 && $diasquefaltam1>=0)){
            $count++;
        }
        else{
            if($dataLimite < $dateToday ){
                if($dataConsulta != "" && $dataConsulta != NULL  ){
                    if(date($dateToday) - date($dataNascimento)<=49){
                    $dataConsulta_2Years = date("Y-m-d", strtotime(date("Y-m-d", strtotime($dataConsulta)) . "+2 year"));
                    $sql2='UPDATE colaboradores set DataConsulta = '.$dataConsulta_2Years.' where ID_colaborador = '.$row1["ID_colaborador"].' ';
                    $result2=mysqli_query($con,$sql2) or die("Query incorrecta: $sql2");
                }
                    else{
                        if(date($dateToday) - date($dataNascimento)>49){
                            $dataConsulta_1Year = date("Y-m-d", strtotime(date("Y-m-d", strtotime($dataConsulta)) . "+1 year"));
                            $sql2='UPDATE colaboradores set DataConsulta = '.$dataConsulta_1Year.' where ID_colaborador = '.$row1["ID_colaborador"].' ';
                            $result2=mysqli_query($con,$sql2) or die("Query incorrecta: $sql2");
                    }
                }
                }    
            }
        }
        $daaf_notificacao = date("Y-m-d", strtotime(date("Y-m-d", strtotime($dataConsultaOcasional)) . " -1 months"));
        $diasquefaltam_Ocasional= (int)((strtotime($dataConsultaOcasional) - strtotime($dateToday))/(60*60*24));
        if($diasquefaltam_Ocasional<=30 && $diasquefaltam_Ocasional>=0 ){
            $countOcasional++;
        }

    }
}

$array = array(
    'Contador' => $count,
    'ContadorOcasional' => $countOcasional

);
echo json_encode($array);

?>

脚本

<script>
    $.ajax({ url: 'loadPaginaUtilizador.php',
        type: 'get',
        dataType: 'json',
        success: function(output) {
            //alert(output);
            $("#counterNotif").text(output.Contador),
            $("#counterNotif2").text(output.ContadorOcasional)
        },
        error: function(e){
           alert(e),
        }

    });
</script>

HTML代码:

<ul class="nav navbar bg-3">
   <li><a href="GestaoAgendamentosPeriodicos.php">Agendamentos Ocasionais &nbsp<i class="icon-globe"></i><span id="counterNotif2" class="notification-counter">0</span></a></li>
 </ul>

问题是,通知始终为0,这一次工作了,而当我使用中间页(按顺序放入数据)来访问该通知时,则停止工作。

你能帮我吗

0 个答案:

没有答案