kehaglund Posted April 5, 2012 Share Posted April 5, 2012 Hello all, I'm relatively new to all of this, but making progress.... I figure this has come up before, but couldn't fin anything by search or browsing. I have an sql table that is cron updated every two minutes from externally generated data in table X columns a,b,c,... . As part of more complicated site, I have one body element page (selected by a tab in the header) that does various sql queries on the data in table X and displays the data. I need this to rerun the queries and update the displayed results every 2 minutes or so as well. However, the standard solutions do not seem to be working: <META HTTP-EQUIV="refresh" CONTENT="15"> A refresh button refreshes the entire site, and not just this element. <FORM> <INPUT TYPE="button" onClick="history.go(0)" VALUE="Force Flight Data Refresh"> </FORM> I hope it is clear. Any ideas of how I could get this to work? Thanks, Kalle Here is a snippet of the code on that page for what it's worth... </head> <body> <div id="header"> <center><h2><font color="red">TRAFFIC INFORMATION</font></h2> </div> <div id="navigation"> </div> <div id="content"> <!-- refresh button --> <FORM> <INPUT TYPE="button" onClick="history.go(0)" VALUE="Force Flight Data Refresh"> </FORM> </center> <?php $IDS->db_build($db); $IDS->db_query($db,$res,"SELECT * FROM `Pilots` WHERE `dest`='KORD'"); echo "<h5>Arrivals to O'Hare:</h5>"; while ($arr_row = mysql_fetch_assoc($res)) { echo "<font color=yellow>".$arr_row['callsign']."</font> using route: ". $arr_row['route']."<br>"; } //end queries //close connect to sql database mysql_close($con) </div> <div id="footer"> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/260419-repeatedly-updating-and-displaying-sql-query-results/ Share on other sites More sharing options...
Psycho Posted April 5, 2012 Share Posted April 5, 2012 You would want to use AJAX for this. Basically the page with have a JavaScript function that will trigger every n seconds to get the new data. The JavaScript will make a request to the server (e.g. PHP code) to get the new data. The PHP code will get the data and return it back to the JavaScript code. The JavaScript code will then take the returned data and repopulate the appropriate content on the page. There are tons of tutorials available out there on how to do this. trying to explain the entire process in a forum post is not realistic. Quote Link to comment https://forums.phpfreaks.com/topic/260419-repeatedly-updating-and-displaying-sql-query-results/#findComment-1334792 Share on other sites More sharing options...
jcbones Posted April 5, 2012 Share Posted April 5, 2012 Your browser is probably caching the page. <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past ?> This should dis-able caching. Quote Link to comment https://forums.phpfreaks.com/topic/260419-repeatedly-updating-and-displaying-sql-query-results/#findComment-1334795 Share on other sites More sharing options...
kehaglund Posted April 5, 2012 Author Share Posted April 5, 2012 Great, thanks very much. Ajax it is! Best, Kalle Quote Link to comment https://forums.phpfreaks.com/topic/260419-repeatedly-updating-and-displaying-sql-query-results/#findComment-1334796 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.