2017-06-14 16 views
0

的index.php如何在更新表时刷新标签数据?

<div class="tab"> 
    <button class="tablinks" onclick="openCity(event, 'Engineering')">Engineering</button> 
    <button class="tablinks" onclick="openCity(event, 'LAW')">LAW</button> 
</div> 

<div id="Engineering" class="tabcontent"> 
    <table class="items"> 
     <tr> 
      <th>State</th> 
      <th>College Name</th> 
     </tr> 
      <?php 
       $query = "select * from college where field = 'engineering'"; 
       $show = mysqli_query($link,$query); 
       while ($fetch = mysqli_fetch_array($show)) 
       { 
      ?> 
      <tr> 
       <td><?php echo $fetch['state']?></td> 
       <td><?php echo $fetch['college_name']?></td> 
       <td> 
        <a href="edit.php?id=<?php echo $fetch['id']; ?>">edit</a> 
       </td> 
      </tr> 
      <?php  
       } 
      ?> 
    </table> 
</div> 
<div id="Law" class="tabcontent"> 
    <table class="items"> 
     <tr> 
      <th>State</th> 
      <th>College Name</th> 
     </tr> 
      <?php 
       $query = "select * from college where field = 'law'"; 
       $show = mysqli_query($link,$query); 
       while ($fetch = mysqli_fetch_array($show)) 
       { 
      ?> 
      <tr> 
       <td><?php echo $fetch['state']?></td> 
       <td><?php echo $fetch['college_name']?></td> 
       <td> 
        <a href="edit.php?id=<?php echo $fetch['id']; ?>">edit</a> 
       </td> 
      </tr> 
      <?php  
       } 
      ?> 
    </table> 
</div> 

edit.php

<?php 
if(isset($_POST['update'])) 
{ 
    $college_name = $_POST['colleges']; 
    $state = $_POST['state']; 
    $sqli = "update college set college_name = '$college_name', state = '$state' where id = '$id'"; 
    $results = mysqli_query($link,$sqli); 
    if($result == true) 
    { 
     $msg .= "<p style='color:green;'>Your data update successfully</p>"; 
    } 
    else 
    { 
     $msg .= "<p style='color:red;'>Errror!</p>"; 
    } 
} 
?> 
<form method="POST" enctype="multipart/form-data" > 
    <select name="state" id="state"> 
     <option value="<?php echo $stateid; ?>"><?php echo $statename; ?></option> 
     <option value="">Select State</option> 
     <?php 
     $sql = "select * from statemaster"; 
     $result = mysqli_query($link,$sql); 
     while($row = mysqli_fetch_array($result)) 
     { 
     echo "<option value=".$row['stateid'].">".$row['statename']."</option>"; 
     } 
     ?> 
    </select> 

    <select name="colleges" id="colleges"> 
     <option value="<?php echo $college_name; ?>"><?php echo $college_name; ?></option> 
     <option value="">Select College</option> 
    </select> 

    <button type="submit" name='update' id='update'>update</button> 
</form> 

在这段代码当我点击编辑按钮,然后就会去edit.php网页,我得到的ID从URL和运行更新查询更新表大学后,数据将更新,但是当我从编辑页面移动到index.php页面时,数据将保持不变,但数据库更新数据将在那里。那么,我该如何解决这个问题?

谢谢

+0

哪里是你的编辑形式?您的更新查询是否有效? –

+0

是的,@Fairy Dancer – omkara

+0

来聊聊天就解释清楚了。 http://chat.stackoverflow.com/rooms/146504/codeigniter –

回答

0

检查缓存。它可能是浏览器不会去服务器以获取index.php的内容,因为它认为它有它。 尝试调用的index.php与变量,如:

<a href="index.php?<?=microtime()?>">Home</a>

+0

或者你可以在你的浏览器中禁用缓存。 –