...

View Full Version : Refresh automaticlly when new results come in.



muggin
12-16-2006, 05:30 PM
I have a simple page that displays the content of a database but I need it to refresh automatically when new entries are submitted. I have tried searching for different tutorials, all of which either do not explain it well enough or it plain do not work, with comments to back it up. I would like to know your take on how to go about doing something like this.

~Thanks in advance

whizard
12-16-2006, 06:57 PM
What about a meta refresh every 30s or something like that?

Dan

muggin
12-17-2006, 05:08 PM
I would really prefer a script that detects when the database is updated and refreshes the results page.

valvet
12-17-2006, 05:12 PM
I would really prefer a script that detects when the database is updated and refreshes the results page.

You should consider using some AJAX-style for that.

I'm using one to update players in my chat.

You could for example make a JS timer that calls Testing() every second. What it does is do a GET request to somefile.php and displays the contents that is echo'ed from somefile.php in the div called myDiv. It doesn't have to be a PHP file tho.



function Testing()
{
var getRequest;

try
{
getRequest = new XMLHttpRequest();
}
catch (e)
{
try
{
getRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
getRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Broken!");
return false;
}
}
}

getRequest.onreadystatechange = function()
{
if (getRequest.readyState == 4) // 4 = complete
{
var ajaxDisplay = document.getElementById('myDiv');
ajaxDisplay.innerHTML = getRequest.responseText;
}
}

getRequest.open("GET", "somefile.php", true);
getRequest.send(null);
return true;
}


Then you could do..

somefile.php


<?php
// do database stuff here.. and echo it out.
echo 'Some random number.. ' . rand(100, 200);
?>


In your HTML file..


<div id="myDiv">
Results will display here..
</div>
<br />
<input id="Submit" type="submit" value="Click me" onclick="javascript:Testing()" />

Something like that..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum