Link to home
Start Free TrialLog in
Avatar of Member_2_6478753
Member_2_6478753Flag for United States of America

asked on

php notification alert when new record is inserted ?

i want to make a alert notification when new message is inserted in the table for example message :


example :

"1 new message in your inbox "

table message : messaeid messagefrom messageto subject content date readflag

please if u can provide to me a example with code..
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

new message is inserted in the table
What table?
Avatar of Member_2_6478753

ASKER

new records inserted on : table name : "message"
Is this a SQL table?
yes i use MSSQL not MYSQL i think the code should be witted using php and ajax?
You can certainly do this in PHP.  PHP knows when a row is inserted into an MSSQL table because PHP is used to call the mssql_query() function. Not sure where AJAX fits in.
i am looking to do like facebook notification system !!!!!!!!!!!!

when new comment is inserted the user who logged receive the  notification
OK, that explains it a little more.  And are you using a framework like WordPress, Joomla or Drupal?
no  i try to add to my  simple cms
sorry i build my own my question how i can make the notification system ? using php ajax... like facebook
How well do you know PHP and JavaScript?
for sure ! i am not beginner !
You can use jQuery to make repeated calls to the server.  On the server, your PHP backend script will check the data base for new elements that match the request. When nothing is found, PHP will simply return a NULL string.  When a new element is found, PHP will return the new element, packaged in the appropriate JSON or HTML.

This answer seems to be pretty on-target:
http://stackoverflow.com/questions/4542863/jquery-ajax-call-with-timer
anyway this not the solution what u have post is a call every 5 or 10 second for example
but what i need is how to get or select the new records !!!!!!!!!! only


if u know the solution provide it i don;t need a part !! ur last answer is just calling a php script that run every X Second !
Repeated calls to the server, using jQuery, are exactly how Facebook does this.  Moreover, Facebook is a PHP machine.  So the recommendation is one that comes to you from a real-life scenario, not something I made up.  I cannot imagine why you would not want to use the method that works for such a successful web site.

This question seems to suffer from a lack of understanding about the nature of HTTP.  The WWW runs over HTTP, so you have to live within its constraints.  In HTTP, you have a client-server protocol.  Clients make requests and servers respond.  Servers do not initiate any action - they only respond.  Every client request is "RESTful," that is to say the request is atomic, complete and stateless.  Every server response is complete and usually instantaneous.  That's all that happens.

Now let's turn to the Web 2.0 look of jQuery/AJAX.  How can the server possibly update the client's viewport spontaneously?  It cannot.  It is a server so it can only provide a response to a request.  The client machine makes a request, but you do not see the request being made because the request occurs as the result of a timer expiration in Javascript.  The timer is only one of many ways to trigger an AJAX request - it can be triggered by onKeyUp (as is the case with Google auto-suggest) or by onClick as shown in this article, or by any JavaScript "event handler" at all.
https://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

The point here should be very clear in your thinking as you design your application.  The nature of HTTP and REST are things outside of your control.  You must work within their designs.  The client request is necessary for the server to make a response.

HTH, ~Ray
greetings afifosh, , depending on the "Amount" of notifications you need to send would make this "not difficult" or "really difficult"  But from your description, you seem to only need to notify a single user, the One whose UserID is used to insert into the "message" table, , You can just use the  UserID  of the one who is getting the Message (NOT the  UserID  of the user posting message), and then use that "User ID" to get the notification path (email or whatever way you do notifications) and send them the notification , using only PHP.
But there may be more or less to how you need to do this? ?
Does what I say so far relate to your problem in your question here?
mmmmm i don't think my question in too hard to solve.. i am planing to get like facebook notfication if someone can provide to me a solution

thank you all :)
What you have here is not a question, it's a requirement for application development.  In respect of your time, I recommend that you hire a professional developer to build your web site.  Otherwise you will need to first invest the time to learn everything the developer knows, then you will invest the time to build the site.  You might be better off saving your time.  Just a thought, ~Ray
ASKER CERTIFIED SOLUTION
Avatar of Member_2_6478753
Member_2_6478753
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The article from elikirk describes a strategy that will cause an infinite loop on the server (but don't worry - your hosting company will kill the process when you try something like this), and the PHP code sample does not even parse correctly.  For anyone reading this question in the future, the correct answers are given here:

ID: 38659014
ID: 38659611

Best regards, ~Ray
this is a simple implementation of notification system !