Apologies if this is a very frequently asked question in here but this is really throwing me off as I can't seem to find where my syntax error is:
<?php require "../connect.php";
$sql = "SELECT pro_exp_date, pro_exp_descr FROM pro_exp";
$result = mysqli_query($connect,$sql);
if ($result->num_rows > 0) :
while ($row = mysqli_fetch_assoc($result)) :
echo "<dt class='col-md-3'>" . $row["pro_exp_date"] . "</dt><dd class='col-md-9'><p>" . $row["pro_exp_descr"] . "</p></dd>";
else :
echo "0 results.";
...
The error seems to begin in line echo "<dt...
, and this is at the start of the page, before there is no semicolons missing or anything like that. Another user in here suggests to use non-bracketed syntax for easier coding, so I did just that. I have changed '
to "
and vice versa in and out of the HTML, nothing works.
ADD: I added endwhile
and endif
and that seems to work, no errors — but I tried reverting back to normal bracket syntax and it threw the error again. I even retraced and rewrote the brackets one by one to make sure everything fits, but that doesn't seem to work. endwhile
and endif
works just fine.
ADD 2:
This works fine:
if ($result->num_rows > 0) :
while ($row = mysqli_fetch_assoc($result)) :
echo "<dt class='col-md-3'>" . $row["pro_exp_date"] . "</dt><dd class='col-md-9'><p>" . $row["pro_exp_descr"] . "</p></dd>";
endwhile;
else :
echo "0 results.";
endif;
This doesn't:
if ($result->num_rows > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<dt class='col-md-3'>" . $row["pro_exp_date"] . "</dt><dd class='col-md-9'><p>" . $row["pro_exp_descr"] . "</p></dd>";
} else {
echo "0 results.";
}
I don't know why. But the endif
and endwhile
works okay.