【问题标题】:Data Tables second table is shown but no reaction数据表第二个表显示但没有反应
【发布时间】:2019-09-13 07:00:35
【问题描述】:

我已经从数据表中实现了一个表 链接 [https://datatables.net/]

我想在一个站点中使用两个表,在 mysqli 连接后的列中具有不同的列和数据 “urlaubstage” -> 是正确的

但是表 2 无论我做什么,即使 var_dump 我也没有得到任何反应,但表格在页面上正确显示但有空列

这是html代码

            <table id="table_id" class="display">
                <thead>
                    <tr>
                        <th>Urlaubstage Jahr</th>
                        <th>Urlaubstage Anspruch</th>
                        <th>Urlaubstage Beansprucht</th>
                        <th>Urlaubstage Rest</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    while($row = mysqli_fetch_array($sql)){
                        $urlaubsTage = $row[4];
                        echo "<tr>";
                        echo "<td>{$urlaubsTage}</td>";
                        echo "<td>Anspruch</td>";
                        echo "<td>Beansprucht</td>";
                        echo "<td>Rest</td>";
                        echo "halllo";
                    }
                    echo "</tr>";
                    ?>
                </tbody>
            </table>
!!!!!!!!!!!!<p>HERE STARTS THE SECOND TABLE</p>!!!!!!!!!!!!!!!!!!!!!!!!
            <table id="table_id2" class="display">
                <thead>
                    <tr>
                        <th>Urlaub Antragsdatum</th>
                        <th>Urlaub Startdatum</th>
                        <th>Urlaub Enddatum</th>
                        <th>Urlaubs Status</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    while($row = mysqli_fetch_array($sql)){
                        var_dump($row); -> EVEn VAR_DUMP IS NOT SHOWN
                        echo "<tr>";
                        echo "<td>Antragsdatum</td>";
                        echo "<td>Startdatum</td>";
                        echo "<td>Enddatum</td>";
                        echo "<td>Status</td>";
                        echo "halllo";
                    }
                    echo "</tr>";
                    ?>
                </tbody>
            </table>

查询代码 ....

$('#table_id').DataTable();
//FUNKTION FÜR ZWEITE TABELLE
$('#table_id2').DataTable();

....

Picture of Code and Table

【问题讨论】:

    标签: php jquery html mysql


    【解决方案1】:

    好的,我自己得到了答案,在第一个循环使用 mysqli_fetch_array($sql) 运行查询 $sql 之后,您不能在第二个循环中再使用它,为什么?导致它在第一个循环及其过度解决方案上运行

    重命名;

    $sql = mysqli_query(同一个查询); $sql2 = mysqli_query(同一个查询);

    第一个循环 while($row = mysqli_fetch_array($sql); 第二个循环 while($row = mysqli_fetch_array($sql2);

    【讨论】:

      【解决方案2】:

      您不需要两次执行相同的查询。您也不需要 while 循环。尝试将结果放入一个数组中,然后多次循环该数组。

      $result = $conn->query($sql)->fetch_all();
      //...
      foreach ($result as $row) {
          //...
      }
      // Repeat the same loop again without calling query again
      //foreach...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-22
        相关资源
        最近更新 更多