dongzhan1948 2016-12-05 11:58
浏览 48

如果我回显“<”,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?

  • 写回答

2条回答 默认 最新

  • dsf5989 2016-12-05 12:04
    关注

    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>
    
    评论

报告相同问题?