Jump to content

outputting a result from sql query


joebudden

Recommended Posts

Hi guys, i've created an application that allows users to upload files into a database

I am now trying to implement code to give each user a maximum file allowance of 5mb.

This is my query so far......

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

How can i output the result of this query to show users how much space they have used????

Iv tried doing print_r($allowance); and echo $allowance; but just outputs resource id #8??


Also will this IF statement be appropriate to check if they have exceeded their allowance????

[code]
if ($allowance + $_FILES['frmFile']['size'] > 5000000)
{
echo 'error';
}
[/code]

at the moment it gives me this error....
 
Undefined index: frmFile in C:\p3t\public_php\cw\LINUX\upload.php on line 14

Please help its stressin me out!!!!!
Link to comment
https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/
Share on other sites

Right i've managed to output the total size of files for each user using this code ...

[code]
<?php
$sql2 = "select sum(size) as totalA from artefact where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";
$allowance = mysql_query($sql2);
$row = mysql_fetch_array($allowance, MYSQL_ASSOC);
echo '<p>You have used ';
echo $row['totalA'];
echo ' of your Allowance</p>';
?>
[/code]

but it displays the total size in bytes , how wud i display it in KB ????

Any ideas ????
OK iv done that pretty easy

[code]
$query = "select sum(size) as total from artefact where dbEmployeeId='".$_SESSION['sessEmployee']['id']."'";
$allowance = mysql_query($query);
$row = mysql_fetch_array($allowance, MYSQL_ASSOC);
echo '<p>You have used ';
echo $row ['total'] /1024;
echo ' KB of your Allowance</p>';
[/code]

Any way of rounding it down as it displays it like this....

        You have used 189.998046875 KB of your Allowance
Do i not use something similar to this ....

[code]
$number=25.66745;
echo "The number = ". $number;              // will display 25.66745
echo "<br>Rounded value of the number = ".round($number,2);    // will display 25.67
echo "<br>Rounded value of the number = ".round($number);    // will display 26
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.