I have a code in php that does a return of data in JSON. When it has only one value it returns as it should:
When more than one value is found it returns as follows:
[ "[email protected]", "[email protected]",].
How do I return it this way?:
Below is the PHP script:
<?php
$lik = mysql_connect("localhost",'root','root');
$link = mysql_select_db('projeto4',$lik);
$search = $_GET['term'];
$qr = "SELECT nome,email FROM usuarios WHERE nome LIKE '%$search%' ORDER BY nome ASC";
$ex = mysql_query($qr) or die (mysql_error());
$resJson = '[';
$first = true;
while($res = mysql_fetch_array($ex)):
if(!$first):
$resJson .= ', ';
else:
$first = false;
endif;
$resJson .= json_encode($res['email']);
endwhile;
$resJson .= ']';
echo $resJson;