更改完成后不显示新数据

时间:2014-11-18 17:34:50

标签: php mysql pdo

我为自己的网页创建了搜索功能,以便更新信息。当我搜索记录并更新信息时。然后返回再次搜索原始信息显示的记录。我检查MySQL数据库,确实显示信息发生变化,不确定为什么会发生这种情况。有人遇到过这个问题吗?

这是我的index.php表格

<!DOCTYPE html>

<html lang="en">
<head>
    <meta charset="UTF-8">

    <title></title>
    <meta content="IE=9" http-equiv="X-UA-Compatible">
    <link href="css/style01.css" rel="stylesheet"><!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
    <h2 style="text-align: center">Inventory Integrity Edit Request
    Form</h2><br>
    <br>

    <div class="wrapper">
        <div class="mainContent">
            <form class="form-horizontal" method="get">
                <div class="form-group">
                    <br>
                    <br>
                    <label class="col-sm-2 control-label" for="id">Enter
                    Request ID #</label>

                    <div class="input-group col-sm-9">
                        <input class="form-control" id="id" name="=id"
                        placeholder="Type the id" type="text"> <span class=
                        "input-group-btn"><button class=
                        "btn btn-default btnSearch" type="button"><span class=
                        "input-group-btn"><span class=
                        "input-group-btn"><span class=
                        "input-group-btn"><span class=
                        "input-group-btn"><span class=
                        "input-group-btn"><span class=
                        "glyphicon glyphicon-search">Search</span></span></span></span></span></span></button></span>
                    </div>
                </div>
            </form>

            <div class="col-sm-2"></div>

            <div class="col-sm-9">
                <!-- This table is where the data is display. -->

                <table class="table table-striped table-hover" id=
                "resultTable">
                    <thead>
                        <tr>
                            <th>Id</th>

                            <th>Name</th>

                            <th>lanId</th>

                            <th>Department</th>

                            <th>Manager</th>

                            <th>Work Requested</th>

                            <th>PO</th>

                            <th>IS</th>

                            <th>Request Comments</th>
                        </tr>
                    </thead>

                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div><!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-1.10.2.js"></script> 
<!-- Include all compiled plugins (below), or include individual files as needed -->
     <script src="js/bootstrap.min.js"></script> <script type="text/javascript">
jQuery(document).ready(function($) {
            $('.btnSearch').click(function(){
                makeAjaxRequest();
            });

            $('form').submit(function(e){
                e.preventDefault();
                makeAjaxRequest();
                return false;
            });

            function makeAjaxRequest() {
                $.ajax({
                    url: 'php/search.php',
                    type: 'get',
                    data: {id: $('input#id').val()},
                    success: function(response) {
                        $('table#resultTable tbody').html(response);
                    }
                });
            }
        });
    </script>
</body>
</html>

这是我的search.php表格

<?php

    require_once 'db_connect.php';
    $conn = dbConnect();
    $OK = true; // We use this to verify the status of the update.
    if (isset($_GET['id'])) {
        // Create the query
        $data = "%".$_GET['id']."%";
        $sql = 'SELECT * FROM requests WHERE id like ?';
        $stmt = $conn->prepare($sql);
        $results = $stmt->execute(array($data));
        $rows = $stmt->fetchAll();
        $error = $stmt->errorInfo();
        //echo $error[2];
    }
    // If there are no records.
    if(empty($rows)) {
        echo "<tr>";
            echo "<td colspan='4'>There were not records</td>";
        echo "</tr>";
    }
    else {
        foreach ($rows as $row) {
            echo "<tr>";
                $id = $row['id'];
                echo "<td><a href='update.php?id=$id'>$id</a></td>";
                echo "<td>".$row['name']."</td>";
                echo "<td>".$row['lanId']."</td>";
                echo "<td>".$row['department']."</td>";
                echo "<td>".$row['mgrname']."</td>";
                echo "<td>".$row['work_requested']."</td>";
                echo "<td>".$row['purchase_order']."</td>";
                echo "<td>".$row['inbound_shipment']."</td>";
                echo "<td>".$row['request_comments']."</td>";


            echo "</tr>";
        }
    }
?>

1 个答案:

答案 0 :(得分:3)

禁用ajax缓存:

$.ajax({
    url: 'php/search.php',
    cache: false,
    type: 'get',
    data: {
        id: $('input#id').val()
    },
    success: function (response) {
        $('table#resultTable tbody').html(response);
    }
});


来自jQuery的{​​{1}} API文档编辑

  

缓存(默认值:true,false,对于dataType'script'和'jsonp')