Hi,
I have the following problem:
I have two fields in a mysql table, uploaded and downloaded and I want to sum them and show the result in a another way, here is my code:
This will echo the value of uploaded field but if I echo $tt_row['uploaded'] + $tt_row['downloaded']; will echo sum of the two fields.
what I am doing wrong?
I have the following problem:
I have two fields in a mysql table, uploaded and downloaded and I want to sum them and show the result in a another way, here is my code:
PHP Code:
function mksize($bytes)
{
if ($bytes < 1000 * 1024)
return number_format($bytes / 1024, 2) . " kB";
elseif ($bytes < 1000 * 1048576)
return number_format($bytes / 1048576, 2) . " MB";
elseif ($bytes < 1000 * 1073741824)
return number_format($bytes / 1073741824, 2) . " Gb";
else
return number_format($bytes / 1099511627776, 2) . " TB";
}
$tt = mysql_query("SELECT * FROM tbl_name WHERE id = ".$USER['id']) or die(mysql_error());
while($tt_row = mysql_fetch_assoc($tt)){
$totaludt = $tt_row['uploaded'] + $tt_row['downloaded'];
$totalud = mksize($totaludt);
echo $totalud;
what I am doing wrong?
Comment