Определенный входной тег был удвоен выходной - PullRequest
0 голосов
/ 12 ноября 2018

Я хочу спросить о моей проблеме с моим выводом.

Я хочу остановить определенную зацикливание обновления в текстовом теге определенного поля, которое моя текстовая строка поиска удваивалась при обновлении определенного 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 голосов
/ 12 ноября 2018

Я думаю, что вы используете одну и ту же страницу для обновления данных, поэтому она обновляет одни и те же данные дважды.

Одна вещь делает другую функцию 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...