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