如果我回显“<”,php echo就会失败

I have a strange problem which I presume is to do with my setup (WAMP on Windows 10). I am a beginner and working on my first project (rewriting an old Access/VBA solution).

I want to create an HTML drop down list on the fly - mysqli_query works fine and I can echo the list I need and get an accurate row count. But when I try any echo statement which starts with a '<' the rest of the page doesn't run.

The < is fine anywhere else but at the beginning. What I need is to be able to put

    while($row = mysqli_fetch_assoc($result)) {
    echo "<option value ='".$row['schoolName']."'>".$row["schoolName"]."</option>";
}

This just displays a list of $row["schoolName"] biut no other text.

There may be some mistakes in that code but I have tested this with much shorter echo strings and they always fail if '<' is the first thing after echo. I don't get an error message - the code above just gives a correct list of $row['schoolName].

Any ideas?

Try this

<select name="" id="input" class="form-control">
<?php
  while($row = mysqli_fetch_assoc($result)) {
  echo "<option value ='".$row['schoolName']."'>".$row["schoolName"]."  </option>";
}
?>
</select>

You must add the <select> tag before using an <option> tag.

<select name="" class="">
<?php
while($row = mysqli_fetch_assoc($result)) {
  echo "<option value ='".$row['schoolName']."'>".$row["schoolName"]."</option>";
}
?>
</select>