PHP脚本,重新加载页面
问题描述:
我在与网页难度不会立即显示更新的数据 这是我目前的一个:PHP脚本,重新加载页面
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hospital", $con);
$result = mysql_query("SELECT * FROM t2");
echo"<br>";
echo"<big>All In Patients</big>";
echo "<table border='1'>
<tr>
<th>Pnum</th>
<th>HospNum</th>
<th>RoomNum</th>
<th>LastName</th>
<th>FirstName</th>
<th>MidName</th>
<th>Address</th>
<th>TelNum</th>
<th>Stat</th>
<th>Nurse</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['PNUM'] . "</td>";
echo "<td>" . $row['HOSPNUM'] . "</td>";
echo "<td>" . $row['ROOMNUM'] . "</td>";
echo "<td>" . $row['LASTNAME'] . "</td>";
echo "<td>" . $row['FIRSTNAME'] . "</td>";
echo "<td>" . $row['MIDNAME'] . "</td>";
echo "<td>" . $row['ADDRESS'] . "</td>";
echo "<td>" . $row['TELNUM'] . "</td>";
echo "<td>" . $row['STAT'] . "</td>";
echo "<td>" . $row['NURSE'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<form>
<input type="button" class='type_button' value="Print" onClick="window.print();" />
</form>
</body>
</html>
你知道什么解决办法,可以使上述更新的代码?因为当我更新数据,然后加载上面的代码。它只会显示尚未更新的先前数据。您必须右键单击并刷新页面以查看效果。
答
您可以尝试设置缓存标头。
<?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
?>
或者您正在从MySQL中获取缓存的数据?
SELECT SQL_NO_CACHE * FROM t2
这是缓存问题吗? – 2010-03-05 13:03:30
你应该在你的代码上面执行UPDATE SELECT,那么它应该工作,如果不是那么问题是在别的地方 – 2010-03-05 13:04:18
不是缓存问题,我试过了下面的代码,但不会工作 – user225269 2010-03-05 23:20:26