I am trying to write a auto complete, which the auto complete items load one time when the PHP page loads. With the items that are fetched from mysql DB , i have create a json array like this
<?php
$bnkArray = array();
$sql_bnk = mysql_query("SELECT BName, BCode, ID FROM bank");
while($rBnk = mysql_fetch_array($sql_bnk)){
$bnkDet = array(
'label' => $rBnk['BName'],
'value' => $rBnk['BName'],
'otherDetails' => $rBnk['BName'].'||'. $rBnk['BCode'].'||'. $rBnk['ID']
);
array_push($bnkArray, $bnkDet);
}
?>
i need this array as like this javascript array
<script>
var bankSource11 = [
{
value: "jquery",
label: "jQuery",
otherDetails: "the write less, do more, JavaScript library",
},
{
value: "jquery-ui",
label: "jQuery UI",
otherDetails: "the official user interface library for jQuery",
},
{
value: "sizzlejs",
label: "Sizzle JS",
otherDetails: "a pure-JavaScript CSS selector engine",
}
];
</script>
if i call this array like this in my auto complete this is not working
var bankSource = [<?php echo $bnkArray; ?>];
what is this array type.. how to do this.
this is the autocomplete part
$(this).autocomplete({
minLength: 0,
source: bankSource,
focus: function( event, ui ) {
$(this).val( ui.item.label );
return false;
},
select: function( event, ui ) {
console.log(ui.item.value +' ____ ' + ui.item.otherDetails);
$( "#project" ).val( ui.item.label );
$( "#project-id" ).val( ui.item.value );
$( "#project-description" ).html( ui.item.otherDetails );
return false;
}
})
}