This question already has an answer here:
I want to use a function inside my loop, in order to print my data in a nice format into my table.
$pdo = Database::connect();
$sql = 'SELECT * FROM data ORDER BY id ASC';
foreach ($pdo->query($sql) as $row) {
function formatSizeUnits($bytes)
{
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2).' GB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2).' MB';
} else {
$bytes = '0 bytes';
}
return $bytes;
}
$bytes = $row['fileSize'];
formatSizeUnits($bytes);
echo('<td>'.$bytes.'</td>');
}
But now I get only the first entry of the database table. How can I get this work?
</div>