Simple script sometimes not working
Hello,
I have problem with very simple script. This code sometimes working, but sometimes I must refresh the page.
Script:
- <script>
- $(document).ready(
- function() {
- $("#loading").fadeOut('normal');
- setInterval(function() {
- $("#battlelist").load("rpsselect.php");
- }, 1000);
- });
- </script>
PHP:
- $pdo = new PDO('there is host, password, user, and db name');
- $stmt = $pdo->prepare("SELECT id, defender, coins, defender_avatar FROM rpsbattles WHERE finished = 'NO' ORDER BY coins DESC");
- $stmt -> execute();
- echo "<div id='battlelist'>";
- while($row = $stmt -> fetch(PDO::FETCH_ASSOC)){
- $defender = $row['defender'];
- $coinsRPS = $row['coins'];
- $avatar = $row['defender_avatar'];
- $id = $row['id'];
- echo "<tr><th style='width: 340px;font-weight: normal !important;'><img src='".$avatar."' style='width:27px;margin-top: -3px;padding-right: 6px;'>".$defender."</th><th style='font-weight: normal !important;'>".$coinsRPS."</th><th><form method='POST'><input type='hidden' name='newID' id='newID' value='$id'><button type='button' name='graj' class='btn btn-primary btn-sm' data-toggle='modal' data-target='.rpsBattle' style='margin-top:-4px;margin-bottom:-3px;'><h5>GRAJ</h5></button></form></th>";
- }
- echo "</div>";