1

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.

2
  • This is bordering on belonging on programmers.stackexchange.com Commented Apr 24, 2012 at 16:30
  • Hey @inkredibly, did you find a solution to this problem? Commented Aug 23, 2013 at 13:15

1 Answer 1

2

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 ......";

?>
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. I see your point, but the problem is that with this we have to send queries, run scripts on the serverside sometimes when there are no updates. I want something on the serverside that say hello there are new records.....
jQuery is not always necessary, it is only one from a really wide range of possibilities. But the worst part in your "solution" is actually a statement that this is "best" method. The second problem is that you actually make OP believe he/she needs to execute whole page and every 10 seconds instead of suggesting more lightweight (response smaller in size, executing only necessary checks on the server) and closer to real time (less impact, so more frequent updates are possible). You do not event mention Comet. The question was serious, response is not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.