3
I have a php code that returns data in JSON.
When it has only one value returns as it should:
When more than one value is found returns as follows:
[, "[email protected]", "[email protected]", ,].
How do I make you come back 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;