html标记在jquery和php中不起作用


html tag not working in jquery and php

我正在尝试使用jquery插件和php进行自动建议。但在jquery中,变量php可以工作,但html不能。我的代码如下:

<?php 
include 'sql.php';
?>
<script>
$(function() {
var availableTags = [
"<?php
    $sql = "SELECT * FROM new_vendor GROUP BY company";
        $result = $cn->query($sql);
            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
            echo $row["company"]."<br>";
                    }} ?>"
 ];
 $( "#tags" ).autocomplete({
 source: availableTags
 });
 });
 </script>
 <div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>

br标记不起作用。请帮助
它给出的结果如下:abcdefsdfass但我需要这样的结果:
abc
def
sdf
ass

它将把<br>回显到浏览器,用HTML术语来说,这意味着呈现一行新行。在这里,您使用的是javascript,html解析器不会对其进行解释。

我想这就是你想要的:

var availableTags = [
<?php
    $sql = "SELECT * FROM new_vendor GROUP BY company";
        $result = $cn->query($sql);
            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
            echo '"' . $row["company"] . "'",'n";
                    }} ?>
 ];