0

I'm trying to get and show total size of row from database,

PHP:

$swall = $db->super_query("SELECT sum(size) as sum FROM dle_photo_post");
$tpl->set("{swall}", $swall['sum']);

With above code, my result is like his: 82447456

Example 2: With this Code:

$swall = $db->super_query("SELECT sum(size)/1024 as sum FROM dle_photo_post");
$tpl->set("{swall}", $swall['sum']);

I got this: 80515.0938

but i need to show total in MB, like this: 80 MB

how i can show total size result in megabyte?

Alireza
  • 1,048
  • 5
  • 18
  • 36

2 Answers2

2
$swall = $db->super_query("SELECT sum(size)/1024/1024 as sum FROM dle_photo_post");
$tpl->set("{swall}", number_format($swall['sum'], 0));

Then you can use number_format (http://www.php.net/manual/en/function.number-format.php) to format the size.

Rainer.R
  • 458
  • 2
  • 8
  • with your help i got a total result like this: 78.62802124, but my problem is i'm not pro with php and i checked your link, but i cant understand how i can convert this numbers to MB! i really appreciate if u helping me more. thanks – Alireza Oct 09 '12 at 07:44
  • I added the number_format line (untested however), does this help? – Rainer.R Oct 09 '12 at 07:47
0

Value is returned in Bytes. You have to divide the value two times with 1024 (B > KB > MB).

(sum(size)/1024)/1024 or $tpl->set("{swall}", ($swall['sum'])/1024);

nirosha rathnayaka
  • 188
  • 2
  • 6
  • 18