$req = mysql_query('SELECT * FROM `name` ORDER BY `id` DESC LIMIT 5;');
if (mysql_num_rows($req) > 0) {
while ($res = mysql_fetch_assoc($req)) {
echo '{
"id": "' . $res['id'] . '",
"ds": "' . $res['ds'] . '",
"sd": "' . ' . $res['sd'] . ' . '"
}, <br/>';
}
}
?>
$strings = [];
while ($res = mysql_fetch_assoc($req)) {
$strings[] = sprintf('{"id" : "%d", "sd" : "%s", "ds" : "%s"}', $res['id'], $res['sd'], $res['ds']);
};
echo implode(',', $strings) . ';';