我在PHP中运行SQL查询并将值放入JS变量:
<?php
$return_arr = array();
$sql="SELECT * from customer_billing group by productname ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
while($result=mysql_fetch_array($rs)) {
$return_arr[] = $result["productname"];
}
echo json_encode($return_arr);
?>
<script type="text/javascript">
$(function() {
var availableTags = <?php echo json_encode($return_arr); ?>
//autocomplete
$(".auto").autocomplete({
source: availableTags
});
});
</script>
我有3行,列productname等于:
当我使用echo json_encode($return_arr);
时,它显示为:
"Integra Fibre Unlimited",null,"Integra Professional Web Hosting"
它只是不喜欢显示第二个
答案 0 :(得分:1)
尝试:
// some code
while($result=mysql_fetch_array($rs)) {
$return_arr[] = utf8_encode($result["productname"]);
}
echo utf8_decode(json_encode($response));