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

重新加载页面的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 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错