CayennneFog
CayennneFog

Reputation: 19

Get a notification on Windows whenever new data is put into my MySQL database

I have a basic local website which uses wampserver and mysql. The point of the website is so that people in my house can request things for me to download for them. They go to the website, input what they would like, and it gets sent to a database table in mysql. I wanted to know if it were possible for me to get a notification on windows or some other means whenever I get new data and how I would go about doing this. I was thinking of maybe setting up a trigger to send new data to my email but I'd much prefer windows notification.

Upvotes: 1

Views: 1234

Answers (2)

Marmik Bhatt
Marmik Bhatt

Reputation: 607

simple way to do this...

What you can do is, you can use Javascript to make ajax API calls to the server in a time loop so if there are notifications are there it shows a popup.

Some basic guidance how to do it...

From Server Side

<?php
$output = array('status'=>0,'message'=>'');
$sql = "SELECT * FROM tbl_notification WHERE notification_tile > Time()";
$query = mysqli_query($conn,$sql);
if(mysqli_num_rows($query)>0){
     //these means there are some notification
    $output['status'] = 200;
    $output['message'] = mysql_fetch_all($query);
}

header('Content-Type:application/json');
echo json_encode($output);

On client side

<div id="notification"></div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    setInterval(function(){
       //this loop will check for updates to the server for notifications
      $.get('server.php',function(data){
         if(data['status']==200){
               //this means there are some notifications available
             $('#notification').html(data['message']['notification_text'];
         }
      });
    },1000);
</script>

note Assuming that you are using jquery for client and PHP for server, and have mysql database with notification table with id, notification_text and notification_time as fields...

Best Luck

Upvotes: 0

usman zafar
usman zafar

Reputation: 230

There are many ways of achieving this (i bet many fellow SO users will advise in this space). But if i were you i would be using an application "telegram" and send the notification when any record is inserted in MySQL.

  1. Telegram: Install the Telegram app
  2. StackOverflow question about posting to telegram

Upvotes: 1

Related Questions