joebudden Posted January 5, 2007 Share Posted January 5, 2007 Hi guys, i've created an application that allows users to upload files into a databaseI 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 14Please help its stressin me out!!!!! Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/ Share on other sites More sharing options...
trq Posted January 5, 2007 Share Posted January 5, 2007 Take a look at [url=http://php.net/mysql_fetch_assoc]mysql_fetch_assoc[/url] and its related functions, your missing quotes a bit.And no, you're if statement makes little sense. Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/#findComment-153216 Share on other sites More sharing options...
joebudden Posted January 5, 2007 Author Share Posted January 5, 2007 can you please enlighten me as to how it should look ??? Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/#findComment-153219 Share on other sites More sharing options...
joebudden Posted January 5, 2007 Author Share Posted January 5, 2007 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 ???? Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/#findComment-153224 Share on other sites More sharing options...
fert Posted January 5, 2007 Share Posted January 5, 2007 divide it by 1000 Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/#findComment-153226 Share on other sites More sharing options...
joebudden Posted January 5, 2007 Author Share Posted January 5, 2007 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 Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/#findComment-153229 Share on other sites More sharing options...
trq Posted January 5, 2007 Share Posted January 5, 2007 [url=http://php.net/number_format]number_format[/url](). Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/#findComment-153233 Share on other sites More sharing options...
joebudden Posted January 5, 2007 Author Share Posted January 5, 2007 yer i'v been trying that , any chance u can code it for me ??? im a bit of a novice lol Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/#findComment-153234 Share on other sites More sharing options...
joebudden Posted January 5, 2007 Author Share Posted January 5, 2007 Do i not use something similar to this .... [code]$number=25.66745;echo "The number = ". $number; // will display 25.66745echo "<br>Rounded value of the number = ".round($number,2); // will display 25.67echo "<br>Rounded value of the number = ".round($number); // will display 26 [/code] Link to comment https://forums.phpfreaks.com/topic/32913-outputting-a-result-from-sql-query/#findComment-153236 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.