RE: [PHP] php mysql live feed



Nameless,

I see someone mentioned the setTimeout(function, milliseconds) function for JavaScript. I would also like to point out that you can use setInterval(function, milliseconds) in order to have an event repeat at a set interval. For instance, let's say you had a page laid out like so:

---
<div id="blah">
Text here
</div>
---

You would want to add a script somewhere that would begin the interval in order to update the div:

---
<script type="text/javascript">
function ajaxRequest()
{
// <insert postback code here>

document.getElementById("blah").innerHTML = ajax.responseText;
}

var t = setInterval("ajaxRequest()", 5000);
</script>
---

This assumes that your XmlHttpRequest object is named "ajax". Assigning the interval to variable "t" ensures that you can clear the interval if you need to (via "clearInterval(t);").

I suppose "innerText" can be used instead of "innerHTML", as well. I would recommend using innerHTML only if you will be populating the div with HTML code, however.

Hope this helps,


Todd Boyd
Web Programmer


-----Original Message-----
From: admin@xxxxxxxxxxxxxxxxxxx [mailto:admin@xxxxxxxxxxxxxxxxxxx]
Sent: Tuesday, May 20, 2008 3:25 PM
To: php-general@xxxxxxxxxxxxx
Subject: [PHP] php mysql live feed

Okay before i pull more hair out...

I am trying to use php to pull mysql data and refresh the mysql data
every say 5 seconds for like a live display of the database without the
screen reloading.

I want the data to refresh but not the screen. Ajax seems to hate me
because everything i have seen/read/tried is wrapped around ASP.NET or
requires a user interaction to invoke the query.

If you have example scripts or a good tutorial that actually works
where you can open a php script and the data changes on the page as the
database does and the screen does not refresh, and you don’t have to
onclick, onfocus, or onblur kind of thing. I would be in your debt

Frustrated Rick

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Relevant Pages

  • Re: [PHP] php mysql live feed
    ... I am trying to use php to pull mysql data and refresh the mysql data every say 5 seconds for like a live display of the database without the screen reloading. ... If you have example scripts or a good tutorial that actually works where you can open a php script and the data changes on the page as the database does and the screen does not refresh, and you don’t have to onclick, onfocus, or onblur kind of thing. ...
    (php.general)
  • RE: [PHP] php mysql live feed
    ... I now have successfully created a live Pika Card status GUI using PHP, MYSQL, AJAX. ... I am trying to use php to pull mysql data and refresh the mysql data ... I want the data to refresh but not the screen. ...
    (php.general)
  • Re: [PHP] php mysql live feed
    ... I am trying to use php to pull mysql data and refresh the mysql data ... I want the data to refresh but not the screen. ... where you can open a php script and the data changes on the page as ...
    (php.general)
  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... This is why I am thinking about rewriting my whole script in a C language. ... Perhaps there are different methods I could be using to speed up execution. ...
    (php.general)
  • Re: How to Add a Feeback Form
    ... I saw nothing in that script that indicates where the form is e-mailed to so ... Greg Maxey/Word MVP ... PHP or not. ... have the support available yet. ...
    (microsoft.public.frontpage.programming)