Administrators Nathan Posted June 14, 2012 Administrators Posted June 14, 2012 I'm trying to find a good tutorial on how to create a spot on my website that will pull in data from a mysql table and auto update without reloading the page. Something very similar to the funtionality of Facebook's News Feed. I can't seem to find anything. Anyone know of any good tutorial on how to accomplish this in PHP? Quote
Administrators Nathan Posted June 14, 2012 Author Administrators Posted June 14, 2012 No one huh? I still haven't found a thing about it online. I maybe searching the wrong things though. Quote
Thomas Posted June 14, 2012 Posted June 14, 2012 Just PHP won't do it you would need JaraScript or something like it to accomplish it. Quote
__Darknite Posted June 14, 2012 Posted June 14, 2012 (edited) Its just basic AJAX. So at the front end you use js via ajax to pull the data and then render it. At the back end you just return the data from mysql query. I'll post later some code examples if you want. Edited June 14, 2012 by __Darknite Quote
Administrators Nathan Posted June 14, 2012 Author Administrators Posted June 14, 2012 Yes please do, I would even be fine just refreshing a div, but having issues getting it done. Trying to do it with this example: http://www.brightcherry.co.uk/scribbles/jquery-auto-refresh-div-every-x-seconds/ But it just continues to return random numbers that refresh. Quote
Thomas Posted June 14, 2012 Posted June 14, 2012 Does this help? http://www.w3schools.com/php/php_ajax_intro.asp Quote
Administrators Nathan Posted June 14, 2012 Author Administrators Posted June 14, 2012 Does this help? http://www.w3schools..._ajax_intro.asp Hah I wish, I need code examples to study. Quote
Marc Posted June 14, 2012 Posted June 14, 2012 (edited) That will help Thomas. It is ajax that you need to be looking for Nathan EDIT: This is the sort of thing you need m8 http://net.tutsplus.com/tutorials/javascript-ajax/build-a-simple-jquery-news-ticker/ Edited June 14, 2012 by Marc Quote
Administrators Nathan Posted June 14, 2012 Author Administrators Posted June 14, 2012 I got it! Ended up using this tutorial, made it real simple. You just keep the portion that needs refreshed in your response.php file and then html in you main .php file that the user hits. This is the javascript code that you put in the beginning of the page: <script> $(document).ready(function() { $("#responsecontainer").load("response.php"); var refreshId = setInterval(function() { $("#responsecontainer").load('response.php'); }, 9000);$.ajaxSetup({ cache: false }); }); </script> This div is in your main .php file the user goes to wherever you want to put it, it will be the div that is refreshed <div id="responsecontainer"> </div> Now after you have that setup, just drop your code you need to be refreshed in your response.php file and wala! Marc 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.