Json编码多个匹配项。

I am building a Jquery/ajax based drop down that retrieves different forms from a database. The "php function" that responds to the ajax call can have to return more then one set of forms depending on the id, meaning there can be more than one record under the same id. The data is then sent back to the script as a Json encoded html table. The question is how would one handle this on the server side. I hope the question is clear.

My code:

<?php
if (!empty($_GET['id'])) {
$id = $_GET['id'];

try {


$objDb = new PDO('mysql:host=localhost;dbname=blankett', 'root', 'root');
$objDb->exec('SET CHARACTER SET utf8');

$sql = "SELECT * 
    FROM `forms`
    WHERE `id` = '$id'";
$statement = $objDb->prepare($sql);
$statement->execute(array());
$list = $statement->fetchAll(PDO::FETCH_ASSOC);



if (!empty($list)) {

   foreach ($list as $row ) {
     $out = array();
     $out[] = '<tr><td><a href="'.$row['link_form'].'">'.$row['name_form'].'</a></td> <td>'.$row['date_added'].'</td></tr>';
   }

  echo json_encode(array('error' => false));
} else {
  echo json_encode(array('error' => true));
}


} catch(PDOException $e) {
echo json_encode(array('error' => true));
}

}else {
echo json_encode(array('error' => true));
}


?>

Well, just echo the array in your json:

echo json_encode(array('error' => false, 'forms' => $out));