Jump to content

Recommended Posts

Hi guys, I've written code to display the total size of files in a database...

[code]
$query2 = "select sum(size) as total from artefact where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";

$allowance = mysql_query($query2);
$a = mysql_fetch_array($allowance, MYSQL_ASSOC);
echo '<p>You have used <b>';
$total = $a['total']/ 1024;
echo round($total);
echo ' KB</b> of your total file size allowance</p>';
[/code]

This works fine...

However I was wondering if there was any way of displaying the size as MEGA BYTES once the total reaches a MEGA BYTE???

I.E IF the total is 200kb it displays 200kb....
   
...but IF the total is 1200kb it displays 1.2mb

Would this be simple to achieve or too complicated ?

Any help appreciated

cheers guys
Link to comment
https://forums.phpfreaks.com/topic/33173-changing-format-of-data/
Share on other sites

no its easy..... i think

all you would bave to do, is once you have the kb count of the file length, you do something like this


[code]
$total2 = total / 1024;

if($total2 > 1) {
echo $total2;
echo "KB</b> of your total file size allowance</p>";}
[/code]

you could use another else if () { } for GB if you really needed


good luck
Cheers PC Nerd GOT IT WORKING ;D

heres the code I used

[code]
<?php
//query to select total size of files in database
$query2 = "select sum(size) as total from artefact where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";

$allowance = mysql_query($query2);
$a = mysql_fetch_array($allowance, MYSQL_ASSOC);
$total = $a['total']/ 1024;
$totalMB = $total / 1024;

//display total size in MegaBytes
if($totalMB > 1)
{
echo '<p>You have used <b>';
echo round($totalMB,2);
echo "MB</b> of your total file size allowance</p>";
}
//display total size in KilaBytes
else
{
echo '<p>You have used <b>';
$total = $a['total']/ 1024;
echo round($total);
echo ' KB</b> of your total file size allowance</p>';
}
?>
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.