JQuery 表没有显示来自 PHP 的任何值

为了分析我的代码问题,我已经挣扎了几个星期,JQuery Pagination表格没有显示 PHP 值。我认为是 PHP 导致了这个问题。


<table class="table">

    <thead>

        <tr>

            <th>ID</th>

            <th>No.</th>

            <th>Nama Mitra</th>

            <th>Jenis Kelamin</th>

            <th>Action</th>

        </tr>

    </thead>

    <tbody>

        <?php

        $i = 1;

        //I think the problem starts here

        while ($rowmitra = mysqli_fetch_array($mitra)) {

            echo '<tr>';

            echo "<th scope='row'>" . $i . "</th>";

            echo "<td>" . $rowmitra['id_mitra'] . "</td>";

            echo "<td>" . $i . "</td>";

            echo "<td>" . $rowmitra['mitra'] . "</td>";

            echo '<td><img width="200px" class="shadow-sm" src="image/logo/' . $rowmitra["logo"] . '"></td>';

            echo '<td><a href="edit-mitra.php?id=' . $rowmitra["id_mitra"] . '"><button>EDIT</button></a></td>';

            echo "</tr>";

            $i = $i + 1;

        }

        ?>

    </tbody>

</table>

这就是我为获取Mitra表所做的工作


$mitra = $koneksi->query("SELECT * FROM `mitra`");

$rowmitra = mysqli_fetch_array($mitra);

我把它放在一个不同的文件中,我使用include 'head.php';命令来合并两者。当我在外部while命令中获取它时,它可以工作。


当我将它放入 .php 时,它没有获取我的 PHP 数组while。我是否笨拙到不知道问题究竟出在哪里?我尝试匹配变量并搜索获取数组的替代方法。但它没有用。


料青山看我应如是
浏览 115回答 1
1回答

尚方宝剑之说

您不应在 while 循环之外声明结果获取数组。删除它$rowmitra = mysqli_fetch_array($mitra);并尝试使用 mysqli_fetch_assoc 来获取数据库列名。&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $mitra = $koneksi->query("SELECT * FROM `mitra`");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $i = 1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //I think the problem starts here&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mysqli_num_rows($mitra) > 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ($rowmitra = mysqli_fetch_assoc($mitra)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<tr>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<th scope='row'>".$i."</th>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<td>".$rowmitra['id_mitra']."</td>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<td>".$i."</td>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "<td>".$rowmitra['mitra']."</td>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<td><img width="200px" class="shadow-sm" src="image/logo/'.$rowmitra["logo"].'"></td>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo '<td><a href="edit-mitra.php?id='.$rowmitra["id_mitra"].'"><button>EDIT</button></a></td>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo "</tr>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $i = $i + 1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?>
打开App,查看更多内容
随时随地看视频慕课网APP