I am working on a small project, and I have code that contains an "if" statement. However, I noticed whenever I fetch data with the value of 0 it does bring it back (var_dump()
) but it doesn't display it because I guess the code thinks it's a useless value?
<?php
include_once 'dbh.inc.php';
$sqli = "SELECT datum, v, vo, nav FROM months;";
$result = mysqli_query($conn, $sqli);
$resultCheck = mysqli_num_rows($result);
echo "<table>";
echo "<tr>";
echo "<th>Datum</th>";
echo "<th> Vakantie uren</th>";
echo "<th> Vakantie uren opgennomen </th>";
echo "<th> Nieuw aantal vakantie uren</th>";
echo "</tr>";
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
if($row['datum'] AND $row['v'] AND $row['vo'] AND $row['nav']) {
echo "<tr>";
echo "<td>".$row['datum']."</td>";
echo "<td>".$row['v']."</td>";
echo "<td>".$row['vo']."</td>";
echo "<td>".$row['nav']."</td>";
echo "</tr>";
}
}
echo "</table>";
}
?>
please notice the if ($row['datum']
etc.
When I take this piece of code out it renders even the values of 0, however if I end up having values that haven't been filled out (for example u have 5 tables in your database and the user fills 4 in because the fifth one is a useless one for him) it fetches the 5th one back as well and I end up having a very ugly empty spot. It doesn't look very nice.
My question is, is there a possible way to tell php (even with an "if" statement) that the value 0 is a value I want displayed?