Ciao a tutti sto elaborando un autocomplete su un campo e per far uscire i risultati mi serve un array in formato jSon.
Il codice che utilizzo è il seguente
Codice PHP:
$q = mysql_escape_string($_REQUEST['q']);
$query = "SELECT UtenteID, UtenteNome FROM Utente WHERE UtenteNome LIKE '%".$q."%'";
$rs = mysql_query($query) or die(mysql_error());
$nr = mysql_num_rows($rs);
$empty = array();
while($rows = mysql_fetch_array($rs)){
$empty["ID"] = $rows['UtenteID'];
$empty["Nome"] = $rows['UtenteNome'];
$empty["Cognome"] = $rows['UtenteCognome'];
}
$json_response = json_encode($empty);
echo $json_response;
il risultato che stampo è il seguente
codice:
{"ID":"1108","Nome":"Francesco","Cognome":null}
Deduco che non funzioni correttamente in quanto mancano le parentesi [ nel risultato.
Come posso modificare il codice per far si che funzioni