I have a php page and in the middle of the page there is a second php page included, similar to below:
<?php
main content page
<?php include 'db-info.php';?>
more content
?>
db-info.php displays a table with information from a database. When the database is updated, I would like the main page to show the updated results. If I have the db-info.php page as a stand-alone page I can make it refresh, but I don't know how to make the db-info.php refresh when it is included in the main content php page.
I would prefer not to constantly scan for changes to the database to trigger the refresh because the database is only updated when a button is clicked. Any ideas for how to link the button click or the database update to make the db-info.php page refresh?
===== edit below ====
Thanks Kaleb and Steven I appreciate your advice. Even though the user clicks a button on the same page where the database info is displayed, the button is created like with document write syntax (this editor won't let me put the actual button code in) the button click triggers a function on a separate javascript file. Kaleb, I can re-write the way that the database information is displayed on the main php page but the main php page does not know that the database has been updated, unless I constantly check the database. The problem is how to trigger the refresh on the main page when the button is clicked or the database is updated. I don't know how to capture that event or whatever to do whatever is needed. The db-info.php page updates when the button in clicked and the database is updated. The db-info.php page is updated but the main content php page still continues to display the same (outdated) db-info.php page that loaded when the main php page was originally loaded.
================= update =====================
I moved the button so that it is on the main content php page. The button triggers the javascript to update the database. Now, since the button is on the same page that has
<?php include 'db-info.php';?>
I should be able to do two things with the onclick, run the javascript and somehow onload and re-load the db-info.php page??? maybe?
============ update ===================== I will re-write the main content php page to build the database info table right into the main page. I will still need a way to refresh that data separately from the entire main page content.
============= please mark this question as answered ===========
I apologize for the lack of clarity in my original question. Also, at first didn't understand the answers that were given but now I realize that they were pointing me in the right direction. Thanks again for the help. I plan to re-write the main content page to display the database info in the innerHTML of a div per the example here:
http://www.w3schools.com/php/php_ajax_database.asp
the db info will be displayed in this div
<div id="dbInfoHere">Database info will be listed here</div>
using this ajax to get the updated info from the database
document.getElementById("dbInfoHere").innerHTML = xmlhttp.responseText;
xmlhttp.open("GET","save-rankings.php?q="+str,true);
in the example, the javascript is called with a select onchange event I can call the javascript from a button onclick event