首页 > 解决方案 > Echo 多个 PHP MySQL 调用未在 HTML 中显示

问题描述

我正在尝试在 PHP 中回显我的 MySQL 数据库中的计数结果,所以它看起来像

学生人数

[#从数据库计数]

但我的 HTML 页面上没有任何内容。我在我的数据库中运行了这个存储过程,我得到了 923,所以我知道它不应该是空的。但是,当我在 HTML 页面上运行它时,它属于“不存在”的情况。我打印到控制台,由于某种原因,它返回为空。

我觉得这可能与这个特定的 php 部分有关,因为我在代码的其他地方运行了另一个 SQL 查询,它工作得很好。我不确定为什么它什么也没返回:

<body>
//////// THIS CALL WORKS FINE AND DISPLAYS RESULTS ////////
<h5>Here is a sample of the first 10 students pulled from the database:</h5>
            <center><?php
            $sql="call DisplayRandomTable('db', 'table', 10)";
            $result = mysqli_query($conn, $sql);
            $resultCheck = mysqli_num_rows($result);

            if ($resultCheck > 0) {
                echo "<table border = '2'>
                    <tr>
                        <th><center>Student ID</center></th>
                        <th><center>Student Name</center></th>
                        <th><center>Student Start Date</center></th>
                    </tr>";
                while ($row = mysqli_fetch_assoc($result)) {
                    echo "<tr>";
                    echo "<td><center>" . $row['STUDENT_ID'] ."</center></td>";
                    echo "<td><center>" . $row['Last_Name'] . "</center></td>";
                    echo "<td><center>" . $row['Start_Date'] . "</center></td>";
                    echo "</tr>";
                }
                echo "</table>";
            }
            ?></center>
////////////////////////////
.
.
.
.
//////// THIS CALL IS WHERE THE ISSUE IS ////////
    <div id="tabs-2" class="tabContent">
        <h3><center>STUDENT DEMOGRAPHY</center></h3>
            <div class="flex-container">
                <div class="flex-item">
                    <h4><center>NUMBER OF STUDENTS</center></h4>
                        <?php
                            // Check connection
                            if ($conn->connect_error) {
                                die("Connection failed: " . $conn->connect_error);
                            }

                            $sql = "call GetTableCount('Students_Information', 'Students')";
                            $result = $conn->query($sql);
                            echo("<script>console.log('The results: " . $result . "');</script>");
                            if ($result->num_rows > 0) {
                                $row = $result->fetch_row();
                                echo 'Total:'. $row[0]; // print total record
                            } 
                            else 
                            {
                                echo 'Nothing exists';
                            }
                        ?>
                    </div>
                </div>
        </div>
</body>

标签: phphtmlmysql

解决方案


推荐阅读