I am running an SQL Query in PHP and putting the values into a JS variable:
<?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>
I have 3 rows with the column productname equal to:
and when i use echo json_encode($return_arr);
, it displays like:
"Integra Fibre Unlimited",null,"Integra Professional Web Hosting"
it just doesn't like displaying the second one
Try:
// some code
while($result=mysql_fetch_array($rs)) {
$return_arr[] = utf8_encode($result["productname"]);
}
echo utf8_decode(json_encode($response));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.