I am running into a problem, i am trying to just query a table and get some result back, if there is no result(empty) then it just echo it is empty.
The problem is, before the while($row = mysqli_fetch_assoc($result)) echo works with no problem. But when it is inside the while loop, it echos nothing back, not even if(mysqli_num_rows($result)==0)echo 'There is nothing'; or if i do
if(empty($result)){
echo "There is no";
Here is my code below, thanks for your time
<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
session_start();
include 'connect.php';
echo "It is working";
$Listingid = "648";
echo "$Listingid";
$result = mysqli_query($con,"SELECT * FROM list WHERE Listingid = '$Listingid'")
or die(mysqli_error($con));
while ($row = mysqli_fetch_assoc($result)) {
if(empty($result)) {
echo "There is no";
} else {
echo 'User ID:' . $row['userid'] . '<br>Username:' . $row['username'] . '<br>Useremail:' . $row['useremail'];
}
}
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);to the top of your code for better error reportingob_start();So you start buffering but never send the buffered output (e.g.echo) to the browser.ob_start(); you have no use for itif(empty($result))BEFORE thewhile-loop, because if$resultis empty, it won't jump into thewhile-loop.