特定的输入标签将输出翻倍

时间:2018-11-12 06:59:27

标签: php jquery html ajax

我想问一下我的输出问题。

我想停止特定字段文本标记中的特定刷新循环,当刷新特定的div时,我的搜索文本栏会加倍。

我已经使用AJAX作为特定div(名称为“ refreshData”)中的刷新器,在这里我只想刷新表输出。

<?php
$conn = mysqli_connect('localhost', 'root', '', 'cardview') or die ("could not connect to database");

 $con=  mysqli_query($conn, "select * from cardprocess");
   ?>

<style>
body {
background-color: #93B0B0;
}

p {
    font-family: 'Century Gothic';
    font-size: 16px;
    text-align: center;
}

input[name=submit] {
    width: 300px;
    background-color: #f2f2f2;
    color: white;
    padding: 8px 15px;
    margin: 8px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Century Gothic';
    font-size: 16px;
}
th {
   background-color: #f2f2f2;
font-family: 'Century Gothic';
    font-size: 19px;
}
td {
   background-color: white;
font-family: 'Century Gothic';
    font-size: 15px;
}
label {
    font-family: 'Century Gothic';
    font-size: 34px;
    }
</style>
<body>
  <input type="text" id="search" placeholder="Type to search"> //Search Box in an outside div
    <div id = "refreshData">
<center>
<p>

      <div class= "caption">
      <h1>View Entry</h1>

<table width="50%" border="3" cellspacing="0" cellpadding="1">   

                    <th>ID</th>
                    <th>NAME</th>
                    <th>TIMESTAMP</th>
                    <th>CURRENT LOCATION</th>
                    <th>STATUS</th> 
            </tr>
            <tbody id = "table">

        <?php

             while($row=  mysqli_fetch_array($con))
             {

                 ?>[enter image description here][1]
            <tr>
                <td><?php echo $row['ID'] . "          ";?></td>
                <td><?php echo $row['Name'] . "        "; ?></td>
                <td><?php echo $row['TimestampNow'] . "        " ; ?></td>
                <td><?php echo $row['Current'] . "        " ;?></td>
                <td><?php echo $row['Status'] . "         " ;?></td>
            </tr>

        <?php

             }
             ?>
         </tbody>
             </table>
            </div>

</p>
<a href = "main2.php"> <input type = "button" name= "submit" value = "BACK"></a>

</center>
</div>

<script src=" https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script> //this is my refresher in an table only
    setInterval(function(){
   $('#refreshData').load('view.php');
}, 4000) 
    </script>
    <script> //codes for filtering search that will show in an table
        var $rows = $('#table tr');
$('#search').keyup(function() {
    var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();

    $rows.show().filter(function() {
        var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
        return !~text.indexOf(val);
    }).hide();
});
    </script>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

我认为您使用同一页面刷新数据,这就是为什么它两次更新相同数据的原因。

做一件事使另一个PHP函数,并仅使用特定的表数据。 喜欢。 Result.php

<php
      $conn = mysqli_connect('localhost', 'root', '', 'cardview') or die ("could not connect to database");
      $con = mysqli_query($conn, "select * from cardprocess");
?>
<center>
<p>

      <div class= "caption">
      <h1>View Entry</h1>

<table width="50%" border="3" cellspacing="0" cellpadding="1">   

                    <th>ID</th>
                    <th>NAME</th>
                    <th>TIMESTAMP</th>
                    <th>CURRENT LOCATION</th>
                    <th>STATUS</th> 
            </tr>
            <tbody id = "table">

        <?php

             while($row=  mysqli_fetch_array($con))
             {

                 ?>[enter image description here][1]
            <tr>
                <td><?php echo $row['ID'] . "          ";?></td>
                <td><?php echo $row['Name'] . "        "; ?></td>
                <td><?php echo $row['TimestampNow'] . "        " ; ?></td>
                <td><?php echo $row['Current'] . "        " ;?></td>
                <td><?php echo $row['Status'] . "         " ;?></td>
            </tr>

        <?php

             }
             ?>
         </tbody>
             </table>
            </div>

</p>
<a href = "main2.php"> <input type = "button" name= "submit" value = "BACK"></a>

</center>

并更新

    <script> //this is my refresher in an table only
    setInterval(function(){
   $('#refreshData').load('view.php');
}, 4000) 
    </script>

<script>
    setInterval(function(){
   $('#refreshData').load('Result.php');
}, 4000) 
    </script>