更新表时如何刷新标签数据?

时间:2017-06-14 07:08:07

标签: php mysqli

的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页面,我从url获取id并在更新table college后运行更新查询数据将更新但是当我从编辑页面移动到index.php页面数据将保持相同,但数据库更新数据将在那里。那么,我该如何解决这个问题?

谢谢

1 个答案:

答案 0 :(得分:0)

检查缓存。可能是浏览器没有进入服务器以获取index.php的内容,因为它认为它具有它。 尝试使用变量调用index.php,例如:

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