I need an json for jquery catcomplete and I would like you to help me...
I have this code
$( ".autocomplete" ).autocomplete({
source: "files/news.php?listar=json"
});
And I would like "files/news.php?listar=json" to display something like this:
[
{ label: "title1", category: "category1" },
{ label: "title2", category: "category2" }
]
Could you please help me?
@edit:
I tried this, but it didn't work:
if ($_GET['listar'] == 'json')
{
echo '['."\n";
$query = mysql_query("SELECT * FROM noticias WHERE deletada='0' ORDER BY id DESC");
$a = 0;
while ($noticia = mysql_fetch_array($query))
{
echo ' { label: "'.$noticia['titulo'].'", category: "'.ucwords(Categoria($noticia['categoria'])).'" }';
$a++;
if ($a < mysql_num_rows($query))
{
echo ",\n";
}
}
echo "\n".']';
exit;
}