我有一个打开弹出窗口的按钮:
<button onclick="loadUsers()">User Accounts</button><br>
loadUsers代码在这里:
function loadUsers()
{
userWindow = window.open("", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=0,left=0,width=900,height=405");
userWindow.document.write("<html><head><link rel='stylesheet'type='text/css' href='css/main.css'><title>Account Management</title></head><body><div class='popup'><?php loadUsersIntoTable(); ?></div></body></html>");
}
正如您所看到的,该文档调用了一个PHP函数loadUsersIntoTable,该函数连接到数据库并检索用户列表,然后将其全部放入表中:
//Preloaded function in PHP, will be called later on
function loadUsersIntoTable()
{
require "db.inc";
//Store the connection in a variable for later use
$conn = mysqli_connect($hostname, $username, $password, $dbname);
//Check for connection
if(!$conn ){
die('Could not connect: ' . mysqli_connect_error());
}
//Define query variable
$query = "SELECT * FROM users";
//Start the query
if($result=mysqli_query($conn,$query))
{
//Create our HTML table start here
echo("<center><table border='1' width='100%'>");
echo("<tr>");
echo("<th bgcolor='#BABABA'>ID</th>");
echo("<th bgcolor='#BABABA'>Name</th>");
echo("<th bgcolor='#BABABA'>Telephone</th>");
echo("<th bgcolor='#BABABA'>DoB</th>");
echo("<th bgcolor='#BABABA'>Address</th>");
echo("<th bgcolor='#BABABA'>Country</th>");
echo("<th bgcolor='#BABABA'>State</th>");
echo("<th bgcolor='#BABABA'>Postcode</th>");
echo("<th bgcolor='#BABABA'>Manage</th>");
echo("</tr>");
while($row = mysqli_fetch_array($result))
{
//Define all variables we will use
$id = $row['ID'];
$name = $row['Name'];
$telnumber = $row['Tel'];
$age = $row['DoB'];
$address1 = $row['Address'];
$country = $row['Country'];
$state = $row['State'];
$postcode = $row['Postcode'];
echo("<tr>");
echo("<td>$id </td>");
echo("<td>$name </td>");
echo("<td>$telnumber </td>");
echo("<td>$age </td>");
echo("<td>$address1 </td>");
echo("<td>$country </td>");
echo("<td>$state </td>");
echo("<td>$postcode </td>");
echo("<td><form method='POST' ACTION='process_deleteuser.php?id=$id'><input TYPE='submit' VALUE='Delete'></form></td>");
echo("</tr>");
}
mysqli_free_result($result); //Free up memory
mysqli_close($conn);
echo("</table></center>");//Close off table now content has been added
}
else
{
echo("Unable to retrieve users from database!");
}
}
但是,当我删除其中一个帐户时,如果我关闭弹出窗口并通过按钮再次重新打开它,我删除的帐户仍然会显示在HTML表格中,但已从数据库中删除....有办法解决这个问题,或者每次弹出窗口都刷新,以便表格刷新?