dimanche 15 avril 2018

HTML inside if statement inside while loop - PHP

I've used html inside loops and if statement before, no problem. But now I got stuck and I can't see what the problem is. I pretty much tried EVERYTHING. I have a while loop and an if statement in it:

while ($row = mysqli_fetch_array($result)) { 
    $gcode = $row ['code'];
    $gname = $row ['gname'];
    $firstletter = substr($gname, 0, 1);
    if ($gid == $firstletter) {?><div>some html</div><?php}
}

It just won't work. No warning message or anything, just a blank page. But if I substitute the html with echo like this, then it works no problem.

while ($row = mysqli_fetch_array($result)) { 
    $gcode = $row ['code'];
    $gname = $row ['gname'];
    $firstletter = substr($gname, 0, 1);
    if ($gid == $firstletter) {echo "some html";}
}

Could anyone please advise. Thank you!

Aucun commentaire:

Enregistrer un commentaire