I'm trying to echo a count result from my MySQL db in PHP, so it looks like
NUMBER OF STUDENTS
[# count from db]
but nothing is coming up on my HTML page. I ran this store procedure in my db and I'm getting 923 so I know it's not supposed to be empty. However, when I run this on the HTML page, it falls into the "Nothing exists" case. I printed to the console and for some reason, it returns empty.
I feel like this might be with this particular php section, because I have another SQL query I run somewhere else in the code and it works just fine. I'm not sure why it's returning nothing:
<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>