как то так
<?php
$q=filter_input(INPUT_GET,'g');
$my_data=mysql_real_escape_string($q);
$mysqli=mysqli_connect('localhost','username','password','databasename') or die("Database Error");
$sql="SELECT id, name FROM tag WHERE name LIKE '%$my_data%' ORDER BY name";
$result = mysqli_query($mysqli,$sql) or die(mysqli_error());
if($result)
{
$i = 0;
$output = '[';
while($row=mysqli_fetch_array($result))
{
$i++;
if($i == 1) {
$output .= '{ "id": "'.$row['name'].'", "label": "'.$row['name'].'", "value": "'.$row['name'].'"}';
} else {
$output .= ',{ "id": "'.$row['name'].'", "label": "'.$row['name'].'", "value": "'.$row['name'].'"}';
}
}
$output .= ']';
}
echo $output;
?>