Autocomplete with categories from database not working

Autocomplete with categories from database not working

I have product names and categories from database fetched with PHP:

$findNames=$user_home->runQuery("SELECT productTitle, category from Iranga "); $findNames->execute(); $information=$findNames->fetchAll(PDO::FETCH_ASSOC); foreach($information as $item){ $namesArray=array("label:"=>$item['productTitle'], "category:"=>$item['category']); }

Then am trying to use collected data like this:

var data=<?php echo json_encode($namesArray);?>;

But it won't work, where could be a problem?

<script>
$(function() {
var data=<?php echo json_encode($namesArray);?>;

$( "#searchTags" ).catcomplete({
options.autocompleteOptions.source = false;
delay: 0,
source: data
});
});
</script>