include ("config.php");
$nid=20;///к примеру
$photo = mysql_query ("SELECT * FROM files WHERE newsid='$nid' ");
$result = '[';
while($wphoto=mysql_fetch_array($photo))
$result .= '{"file":"files/'.$wphoto['filename'].'","id":"'.$wphoto['id'].'"},';
echo rtrim($result,',') . ']';