Displaying Notification when new data is entered by admin into the table.

ref: http://ned.im/noty/

i m trying to use this design.
but how do we trigger? i building site using dw c6. have complete knowledge in html & bit about php.

site is built on php & html.
 so how can we trigger when new data is entered in certain table?
Mohammed KumelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MlandaTCommented:
How does data get written to the "certain table"? Is it through you app as well? If it is, then I suggest this approach:

Assumptions:
You want notifications to happen in real time. So a user might be working on whatever else, BUT once that data is written into the table, you want them to get a notification saying data has been written to the database.
You want the web server to push the message to all the users.
One of your pages is responsible for writing data to the table

Approach: WebSockets
References: http://www.bennadel.com/blog/2351-coldfusion-10---using-websockets-to-push-a-message-to-a-target-user.htm, http://en.wikipedia.org/wiki/Web_socket

Server Side:
1 - Create your web sockets infrastructure (the posted article is well documented and available on GitHub)
2 - In your page where records are written to the table (on each successful INSERT/UPDATE or whatever), use the web socket to broadcast a message to all connected users

Client Side:
3 - Add the noty infrastructure (javascript + css references etc). This is detailed on the noty page.
4 - Add code which establishes a channel connection (ideally to each page that may received messages). Depending on your page structure, the best place to add this is to a header/footer section which gets included on all your pages in the site. So that there is only one place to maintain this.
5 - In the socket.on (http://www.bennadel.com/blog/2351-coldfusion-10---using-websockets-to-push-a-message-to-a-target-user.htm => main.js line 42) instead of writing the message to the console (console.log( "Published:", data );) you issue a noty (var n = noty({text: data});)

NOTE: Of course if users are not logged on OR they are busy doing a page refresh they will miss any notifications :) We are not caching notifications on the server side or anything fancy like this. This is 100% real time.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mohammed KumelAuthor Commented:
testing.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Testing</title>
</head>

<body>
<div id="result"></div>

<?php include 'Connections/con1.php';?>

<script>
if(typeof(EventSource)!=="undefined")
  {
      var source = new EventSource("demo_sse.php");

  source.onmessage=function(event)
    {
    document.getElementById("result").innerHTML+=event.data + "<br>";
    };
  }
else
  {
  document.getElementById("result").innerHTML="Sorry, your browser does not support server-sent events...";
  }
</script>
</body>
</html>

Open in new window


demo_sse.php:

<?php
include 'Connections/con1.php';
 
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
 
mysql_select_db($database_con1, $con1);
$query_Areas = "SELECT * FROM Areas";
$Areas = mysql_query($query_Areas, $con1) or die(mysql_error());
$row_Areas = mysql_fetch_assoc($Areas);

<!-- codes for displaying data goes here -->

flush();
?>

Open in new window


When new records are added here i want it to show as notification.
Table Areas got following columns:
ID
AreaName
Message


Regards
0
Mohammed KumelAuthor Commented:
con1:
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_con1 = "localhost";
$database_con1 = "lotomanager";
$username_con1 = "root";
$password_con1 = "";
$con1 = mysql_pconnect($hostname_con1, $username_con1, $password_con1) or trigger_error(mysql_error(),E_USER_ERROR);
?>

i want it to work on php & nothing else.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

MlandaTCommented:
Oh dear! i wonder why I was thinking ColdFusion and not PHP! You clearly state that it's PHP! I'll find some PHP examples for you. The model I propose still works, just  a different language.
0
Mohammed KumelAuthor Commented:
waiting eagerly. :(
0
MlandaTCommented:
Here is a sample:

http://www.abrandao.com/2013/06/25/websockets-html5-php/

It would be good if you worked through that and familiarised yourself with the idea. Then see if you can implement this in your app.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.