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:
- Integra Fibre Unlimited
- Integra Fibre Unlimited (RRP: £59.95)
- Integra Professional Web Hosting
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