1

I am building a weather station that will update the weather in "real-time" to a MySQL Database. To give the feel of "real-time" without taking up a ton of space on my MySQL server, I have my weather station updating a single cell in the MySQL database every few seconds. I would like to set up a way for a website to view this change in realtime without refreshing the page. I have tried researching a lot, but I can't quite find what I am looking for (at least with more of an explanation into the JQuery and how it works). Most answers have partial as people have a lot more experience.

I have a little experience with PHP and MySQL (I have just started learning a couple of months ago). This project is more of a way to learn JQuery and AJAX (along with PHP and MySQL). Frankly, I don't know a ton as I am just starting into programming.

If I could get a bit more of an explanation into how the JQuery works and what files I need to be placing the information in, that would be great (a lot of other similar answers had a separate "server" file and a "client" file in PHP. Do I really need that?).

I just don't know where to begin or what to put in what files. Maybe I need a tutorial? Thanks.

harrisbmark
  • 13
  • 1
  • 1
  • 4
  • The way AJAX and jQuery works with PHP and mySQL is by letting your bridge the gap between what you see on the website (Client) and Server. You can make AJAX calls to a PHP file that in turn connects to a database to retrieve data, from there you return the data to the AJAX function and you can use that data in jQuery to update the data on the website by changing values of elements – Chitowns24 Mar 15 '14 at 05:37
  • Since you mentioned "change in real time without refreshing the page" I guess what you're looking for is how to push data from web server to browser. It is not a common scenario for jquery and AJAX. You may want to look at the links in this question: http://stackoverflow.com/questions/16122911/efficient-reloading-data-pushing-data-from-server-to-client On the other hand `node.js` would fit well for your scenario but you need to know javascript on intermediate level. – Alex P Mar 15 '14 at 13:33

2 Answers2

2

I think what you are looking for is "Push Technology". But, as a beginner like me, I would introduce you to try out "long pulling". Although is not the best method, you can learn how real-time update works.

I suggest you create a normal working AJAX, then use the code below to repeatedly call for updates from the server.

jQuery(document).ready(function () {
    interval =  setInterval("checkNewUpdate()",4000); //Set interval for accident checking ajax
}

This function basically retrieves information from the database every 4seconds. This method is not so efficient, but I hope would help you to kick start in push technology.

Visit How do I implement basic "Long Polling"? for more information.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Eddy Goh
  • 256
  • 5
  • 11
0

I suggest you to create a function to check database status, something like count row in the database or something else like that... the return must be simple a data like number , true or false (not a long data) with interval .. and when it change the fetch function will run