RIRedinPA Posted October 22, 2009 Share Posted October 22, 2009 What is a good way to refresh my page when the database changes (either by an insert or an update)? Link to comment https://forums.phpfreaks.com/topic/178633-refreshing-page-when-database-updates/ Share on other sites More sharing options...
mrMarcus Posted October 22, 2009 Share Posted October 22, 2009 use header() function. Link to comment https://forums.phpfreaks.com/topic/178633-refreshing-page-when-database-updates/#findComment-942221 Share on other sites More sharing options...
PFMaBiSmAd Posted October 22, 2009 Share Posted October 22, 2009 Browsers, no matter how hard you try, can only function as the client in a HTTP request/response client-server arrangement - http://en.wikipedia.org/wiki/HTTP You need to cause the client (browser) to make periodic http requests to the server in order to get the current information. If you use AJAX, you can then update the information on the page without refreshing the whole page or needing to send all the content that makes up the page (only the changed information needs to be sent.) The database server and the web server cannot actually cause anything to happen on a web page that has been rendered in a browser when an action or event occurs in the database, even if you have a database that supports doing something when an action or event is triggered in the database. Link to comment https://forums.phpfreaks.com/topic/178633-refreshing-page-when-database-updates/#findComment-942224 Share on other sites More sharing options...
RIRedinPA Posted October 22, 2009 Author Share Posted October 22, 2009 Thanks, I should have provided more details... I have an AppleScript that idles (think cron) every minute and checks to see if iTunes has changed songs, if so it then updates a small database I have with the artist, song title and album, this database is being read and displayed from a PHP page. On that page I'd like to either have it change the displayed data when the db is updated or do something similar to cron/idle and read and display the db data on some sort of timed loop (say also every minute). Link to comment https://forums.phpfreaks.com/topic/178633-refreshing-page-when-database-updates/#findComment-942225 Share on other sites More sharing options...
RIRedinPA Posted October 22, 2009 Author Share Posted October 22, 2009 Browsers, no matter how hard you try, can only function as the client in a HTTP request/response client-server arrangement - http://en.wikipedia.org/wiki/HTTP You need to cause the client (browser) to make periodic http requests to the server in order to get the current information. If you use AJAX, you can then update the information on the page without refreshing the whole page or needing to send all the content that makes up the page (only the changed information needs to be sent.) The database server and the web server cannot actually cause anything to happen on a web page that has been rendered in a browser when an action or event occurs in the database, even if you have a database that supports doing something when an action or event is triggered in the database. Thanks, that's kind of where I was thinking (see my other, more detailed post) but I'm not aware of anything in PHP that would allow me to do a timed loop such as you can do in AppleScript. Would a Javascript like this work? window.onload = timerMethod; function timerMethod() { clearInterval(timerId); //AJAX stuff here } var timerId = setInterval(timerMethod, 60000); Link to comment https://forums.phpfreaks.com/topic/178633-refreshing-page-when-database-updates/#findComment-942230 Share on other sites More sharing options...
PFMaBiSmAd Posted October 22, 2009 Share Posted October 22, 2009 There are a ton of existing scripts - http://www.dynamicdrive.com/dynamicindex17/indexb.html (see any of the 'ticker'/'scroller' scripts at that link) Link to comment https://forums.phpfreaks.com/topic/178633-refreshing-page-when-database-updates/#findComment-942236 Share on other sites More sharing options...
RIRedinPA Posted October 22, 2009 Author Share Posted October 22, 2009 There are a ton of existing scripts - http://www.dynamicdrive.com/dynamicindex17/indexb.html (see any of the 'ticker'/'scroller' scripts at that link) Thanks, I should be able to put together what I need from that. Link to comment https://forums.phpfreaks.com/topic/178633-refreshing-page-when-database-updates/#findComment-942240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.