c_pattle Posted June 19, 2010 Share Posted June 19, 2010 I have a script that returns a random record from a database each time you refresh the page and adds it to the content so the list gets longer and longer. However am I able to make it so that it runs the query of refreshes the page after a certain amount of time such as 5 seconds? If you're not sure what I mean I'm trying to get a similar effect to the twitter homepage where is display a random tweet after a certain amount of time. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/205252-execute-query-after-certain-amount-of-time/ Share on other sites More sharing options...
theverychap Posted June 19, 2010 Share Posted June 19, 2010 I would suggest using javascript (jQuery is an excellent library) to call your php script every n seconds and append the returned data to the page... Something like: setInterval("$('#container').load('phpscript.php')", 5000); Quote Link to comment https://forums.phpfreaks.com/topic/205252-execute-query-after-certain-amount-of-time/#findComment-1074351 Share on other sites More sharing options...
c_pattle Posted June 19, 2010 Author Share Posted June 19, 2010 Thanks for the advice. Although does this refresh the page. Would you reccomend using JQuery over Ajax? Quote Link to comment https://forums.phpfreaks.com/topic/205252-execute-query-after-certain-amount-of-time/#findComment-1074436 Share on other sites More sharing options...
Alex Posted June 19, 2010 Share Posted June 19, 2010 JQuery and AJAX are completely different things. JQuery is a popular JavaScript library that implements easy ways to utilize AJAX technology. The load method used in theverychap's post above is an example of one of these easy methods. Quote Link to comment https://forums.phpfreaks.com/topic/205252-execute-query-after-certain-amount-of-time/#findComment-1074439 Share on other sites More sharing options...
c_pattle Posted June 19, 2010 Author Share Posted June 19, 2010 Yeah I know, but Ajax is for updating pages without refreshing the page so do you reccomend I learn it for future cases like this? Quote Link to comment https://forums.phpfreaks.com/topic/205252-execute-query-after-certain-amount-of-time/#findComment-1074440 Share on other sites More sharing options...
Alex Posted June 19, 2010 Share Posted June 19, 2010 Yeah I know, but Ajax is for updating pages without refreshing the page Well isn't that what you want to do? If so then yes you should learn how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/205252-execute-query-after-certain-amount-of-time/#findComment-1074441 Share on other sites More sharing options...
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.