0

For example, I have the following data

Name        Date  
Aplha    10/05/1988 
Bravo    10/04/1999
Charlie  10/08/1990

I'm trying to make a auto check data (database) for every minute, and compare it with the current Date on the computer, if its the same, I can insert message like happy birthday.

Someone can provide reference or solution to this, would be appreciated. its like notification but in this case it will send message automatic

edited note - nvm i got it..updated script

my js

$(function()
{

setInterval(function() {
    $.ajax({
        url: "dooBday.php",
        success: function (data) {
            $("#feedback").html(data);
        }
    });
}, 1000 * 60);


});

my dooBday function

$tgl=date("d/m");
$tglInt=date("d/m");
$tglInt=preg_replace( '~\D~', '', $tglInt);
$tglInt=intval($tglInt);

// Database Object
$tablename = "Phonebook_New";
$tablename2 = "USER_ID";
$xo=0;
$xx=0;
$VinDB = new VinDB();

// Get Data
$query2 = "SELECT * FROM ".$tablename2." WHERE UserID='".getMultiUserID()."'";
$result2 = $VinDB->query($query2);

if ($VinDB->num_rows($result2) != 0)
{
    $line2 = $VinDB->fetch_array($result2);

    if($line2["bdaySts"]==1 and strlen(trim($line2["bdayMsg"])) > 0){

    // Get Data--------------------------------
    $query = "SELECT * FROM ".$tablename." WHERE User_ID='".getMultiUserID()."' AND bdaySent='x'";
    $result = $VinDB->query($query);

    if ($VinDB->num_rows($result) != 0)
    {
    while ($line = $VinDB->fetch_array($result))
    {

        if(!empty($line["Ultah"])){

        $tglNew=substr($line["Ultah"], 0, -5);
        if($tgl==$tglNew){

            $datex = date('Y/m/d');
            $timex = date('H:i:s');
            $schedule= date($datex . '-' . $timex);

        //doo Update Contact Sent--------------------   
        $sqlquery[$xo]="UPDATE ".$tablename." SET bdaySent='Sent' where User_ID='".getMultiUserID()."' and nomor='".$line["nomor"]."'";
        $xo++;

        // doo Send Message----------------------------
            $inuquery[$xx] = "INSERT INTO Schedule ";
            $inuquery[$xx] .= "(message,phone_number,Schedule,Status,User_ID) ";
            $inuquery[$xx] .= "VALUES ('".$line2['bdayMsg']."','".$line['PhoneNumber']."','".$schedule."','Processing','";
            if (isset($_SESSION['user_id2']))
            {
                $inuquery[$xx] .= $_SESSION['user_id2']."')";
            } else {
                $inuquery[$xx] .=  "Unknown')";
            }
            $xx++;

        }}

    }//end while

    }// end if

    }

}//end send bday

for($i=0;$i<$xo;$i++){

    $result = $VinDB->query($sqlquery[$i]);
    $result2 = $VinDB->query($inuquery[$i]);
}
Runshax
  • 117
  • 2
  • 13

1 Answers1

0

I think you want to wish users. If I am right. You can do it like this.

put this code on your page where you would like to check every minute

setInterval(function() {
    $.ajax({
        url: "ajx.php",
        success: function (data) {
            $("#feedback").html(data);
        }
    });
}, 1000 * 60);

And this will be your ajax.php file

<?php
// Name        Date  
// Aplha    10/05/1988 
// Bravo    10/04/1999
// Charlie  10/08/1990

$alphaDob = '02/04/1988';
$exp = explode('/', $alphaDob);

$userDate = $exp[0];
$userMonth = $exp[1];

$currentDate = date('Y-m-d');
$exp = explode('-', $currentDate);

$currentDate = $exp[2];
$currentMonth = $exp[1];

if($currentMonth == $userMonth && $currentDate == $userDate) {
    echo 'Happy Birthday';
} 

For good performance use Ajax-Long-Polling function, example can be found here Long-Polling Example

Community
  • 1
  • 1
zarpio
  • 10,380
  • 8
  • 58
  • 71
  • yes make wish to user, but i'm trying to make a automatic check data , so if the user loads the page and waits in that current page, a script will run for every 1min/2min like a notification, but in this case it will automatic send message – Runshax Apr 02 '14 at 11:51
  • i tried it, it worked, but in testing data i only got 1 update query per minute, i'll post my script – Runshax Apr 04 '14 at 02:10
  • I am not getting your point, but if you want multiple users data at a time you should use json to get multiple records. – zarpio Apr 04 '14 at 09:38
  • its ok i got it, just need array – Runshax Apr 04 '14 at 10:53