php - 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>
解决方案
推荐阅读
- ios - 如何使用 UIKit 在图像下添加一些文本
- node.js - yargs 支持最低 Node.js 版本 12 - Jenkins
- c - 结构指针未按预期保存字符数组
- node.js - 反应向 API 发送空对象而不是 formData
- amazon-web-services - AWS EBS Nextjs 应用程序不适用于自定义域
- sql-server - SQL Server DENSE_RANK 返回错误结果
- lua - 将字符串保存在 lua 表中
- git - 是否可以像使用 Visual Studio Code 一样使用 Git SVC 在 Visual Studio(社区)中对文件进行一些更改?
- php - phpmailer 可以在本地主机上工作,但不能在实时服务器上工作,我在 (000webhostapp.com) 上使用免费域
- html - 如果在新行中,如何使元素的宽度为 100%?