javascript - 无法自动刷新 HTML 中的两个表

标签 javascript php mysqli html-table

我想问一下,为什么我无法刷新两个html表格?只有1个? Javascript代码有问题吗?我已经尝试声明 2 个变量,并尝试为每个变量创建脚本,但仍然没有运气,我尝试将变量名称更改为唯一的变量,但仍然没有运气。我的完整代码如下:

    <!-- SALES.HTML -->
    <div class="col-sm-5 shadow">
            <p>
              <h3><center>Hyukies</center></h3>
              <center>Catbalogan, City</center>
              <center><span class="glyphicon glyphicon-time"></span>&nbsp;<?php include('time.php'); ?></center> <br />

               <div id="transactions_left">
                    <?php include_once('salestable.php')?>
                </div>
            </p>

        <div class="row">
                  <div class="col-sm-12"><b>
                      <p>

                    <?php include_once('sales_count.php')?>

                            <script>
                                var table = $("#salestableid");
                                    var refresh = function() {
                                      table.load("salestable.php", function() {
                                        setTimeout(refresh, 1); 
                                      });
                                    };
                                refresh();

                                var table1 = $("#sales_countid");
                                    var refresh1 = function() {
                                      table.load("sales_count.php", function() {
                                        setTimeout(refresh1, 1); 
                                      });
                                    };
                                refresh1();
                            </script>

                        <button type="button" class="btn btn-danger btn-md" data-toggle='modal' data-target='#cancel'>Cancel</a>
                        <button type="button" class="btn btn-warning btn-md" data-toggle='modal' data-target='#hold'>Hold</button>
                        <button type="button" class="btn btn-success btn-md pull-right" data-toggle='modal' data-target='#payment' >Payment</button>
                        <br /><br />
                        <center>Thank you and have a Nice day!</center>

                    </p>
                </div>
        </div>
    </div>

    <!-- End of Page SALES.HTML -->



    <!-- SALESTABLE.PHP -->

        <?php require_once("../includes/db_connection.php"); ?>
               <table class="table table-hover" id='salestableid'>
                    <thead>
                            <tr class= "default" style="background-color: #e18728">
                                <th><font color = "white">Action</font></th>
                                <th width="200"><font color = "white">Product</th>
                                <th><font color = "white">Quantity</th>
                                <th width="75"><font color = "white">Price</th>
                                <th width ="90"><font color = "white">Total</th>
                            </tr>
                    </thead>
                <tbody>
                      <tr>
                                                            <?php
                                                                $user_query = mysqli_query($connection, "SELECT saleslog.itemid, saleslog.qty, saleslog.date, saleslog.total, saleslog.id, items.`name`, items.description, items.retailprice FROM saleslog LEFT JOIN items ON items.id = saleslog.itemid")or die(mysqli_error());
                                                                while($row = mysqli_fetch_array($user_query)){
                                                                $id = $row['id'];
                                                            ?>

                                                        <tr>
                                                            <td><a href="delete_salesitem.php?id=<?php echo urlencode($row['id']); ?>" class="btn btn-danger glyphicon glyphicon-trash btn-xs"></a></td>
                                                            <td><?php echo $row['name']; ?></td>
                                                            <td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<?php echo $row['qty']; ?></td>                   
                                                            <td>&nbsp<?php echo number_format($row['retailprice'],2); ?></td>
                                                            <?php 
                                                                $total = $row['qty'] * $row['retailprice'];
                                                            ?>
                                                            <td><?php echo number_format($total,2); ?></td>
                                                        </tr>
                                                        <?php } ?>

                    </tr>
                </tbody>
            </table>

    <!-- End of Page SALESTABLE.PHP -->



    <!--SALES_COUNT.PHP -->
    <?php require_once("../includes/db_connection.php"); ?>

                           <?php    
                               $count_client= mysqli_query($connection, "SELECT * FROM saleslog");
                               $count =  mysqli_num_rows($count_client);
                           ?>

                            <?php   
                                $totalsales= mysqli_query($connection, "SELECT SUM(total) AS totalpritems FROM saleslog");
                                while($totalperitems = mysqli_fetch_array($totalsales)){
                                $total_sales = $totalperitems['totalpritems'];
                                }
                           ?>


        <table class='table' style="border-style: dotted" id="sales_countid">
          <tr class='' style="border-style: dotted">
            <td width="50" >Total Items: </td>
            <td width="50"align="right"><?php echo $count; ?></td>
            <td width="50" >Total: </td>
            <td width="50"align="right" >P <?php echo number_format($total_sales,2); ?></td>
          </tr>
          <tr class='' style="border-style: dotted">
            <td width="50">Discount: </td>
            <td width="50"align="right">0.00 </td>
            <td width="50">Tax: </td>
            <td width="50"align="right">0.00 </td>
          </tr>
          <tr style="border-style: dotted">
            <td width>Total Payable: </td>
            <td align="right">P <?php echo  number_format($total_sales,2); ?></td>
            <td></td>
            <td></td>
          </tr>
        </table>
    <!--End of Page SALES_COUNT.PHP --> 

最佳答案

table1 的刷新代码中,您改为刷新 table

table1.load(...) 而不是下面代码中的 table.load(...)

var table1 = $("#sales_countid");
var refresh1 = function() {
    table.load("sales_count.php", function() {
    setTimeout(refresh1, 1); 
    });
};

关于javascript - 无法自动刷新 HTML 中的两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29791332/

相关文章:

php - mysqli INSERT 查询不工作没有错误

php - MySQLI通过socket连接本地服务器错误

javascript - 模仿 Angular 元素上的点击

javascript - 一页上的 2 个轮播 slider 不起作用

php - Laravel:在重新播种表之前重置自动增量

php - MySQL查询顺序按“最完整的字段”

php - 为什么从 URL 参数值保存数据到 MySQL 失败?

javascript - 如何动态地将 json 对象值传递给 php?

javascript - 响应式网页 : SVG visualization?

php - 找到所有的 <img> 标签,去掉 height 和 width 然后把去掉的值放在 <img> 标签的样式中