Quote:
Originally Posted by archive02
The counter at the bottom of my website needs to be updated dynamically using the count() from MySQL and PHP. Now, how do I update this on the page without the user having to reload? I'm a bit confused on how to have JavaScript execute PHP code without forwarding the user to the new page.
Anyone know how this is done?
|
What you'll need to do is probably setup a php script that will retrieve your count() and echo it. Then what you could do is have a JavaScript counter call that php script every 5 seconds (for example). Using AJAX you will be able to retrieve the value echoed from your php script in a JavaScript variable. I strongly recommend using
prototype.js for ajax, it really takes care of handling all of the ugly XMLHTTPRequest stuff. It sounds like, if you're only going to be retrieving a counter you may want to use JSON...that way you will not have to parse XML in your JavaScript.
I know all of that is at a pretty high level, but I'm not sure where you're at as far as familiarity with JavaScript and AJAX. Let me know if you need more detail, I'd be glad to elaborate and post some code examples.
Happy Coding!
-Fahlyn