duanqie5741 2010-03-05 12:59
浏览 28
已采纳

重新加载页面的php脚本

I'm having difficulty with pages that does not show the updated data immediately Here's my current one:

<?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>

Do you know of any workaround that could make the code above updated? Because when I update the data and then load the code above. It will only show the previous data which has not been updated yet. You will have to right click and refresh the page in order to see the effects.

  • 写回答

1条回答 默认 最新

  • dpowt82802 2010-03-05 13:07
    关注

    You could try to set cache headers.

    <?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
    ?>
    

    Or maybe you are fetching cached data from the MySQL?

    SELECT SQL_NO_CACHE * FROM t2
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?