Inkredibly
Inkredibly

Reputation: 11

Real time data display using Ajax and PHP

I intend to create a web interface to display data from a database in real-time. The data comes from monitoring devices and is then stored into the database by a software component independent from mining and I can access neither its configuration file nor its source code. I intend to use Ajax/PHP to display the data on the web interface and as I think I will have both JavaScript and HTML and PHP in the same piece of code, I thought design patterns may help.

Do you have any implementation idea on how I could have the new records and all updates displayed in the website without refreshing the page and in real time? Which design pattern could help (either on the server side or on the client side)? Could it be useful to use the observer pattern to observe a PDO?

NB: I've just had some JavaScript Ajax courses and I only have theoretical knowledge of the design patterns, but I'm familiar with OOP.

Upvotes: 1

Views: 12512

Answers (1)

Raphael1
Raphael1

Reputation: 84

Best way would be to use JQuery to check a php script every few seconds and then fresh a div

Place that in between your head tags

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_updates').load('myphpfile.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds

</script>

place in main body(every new updates will be displayed in that div)

<div id="load_updates"> </div>

your php file could look like this, ever thing that is echoed out will be appear in the div in you main page. You can run queries then echo the data.

<?php

echo "Testing ......";

?>

Upvotes: 2

Related Questions