vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   Attachment Count in MB (https://vborg.vbsupport.ru/showthread.php?t=53416)

Boofo 05-26-2003 07:56 PM

Attachment Count in MB
 
Can anyone please tell me how to pull the MB out of an attachment query? Here is the code for pulling out the KB but I can't seem to find the right code for the MB. I know it is simple, but I must not be very good in the math department.

PHP Code:

SUM(LENGTH(attachment.filedata))/1024 AS KBbytes 


assassingod 05-26-2003 08:06 PM

PHP Code:

SUM(LENGTH(attachment.filedata))/1048576 AS KBbytes 

?:confused:

Boofo 05-26-2003 08:19 PM

I had that but I want to get it like 2.12 MB. instead of just 2 MB. How do I get it to go the 2 decimal places?

filburt1 05-26-2003 08:39 PM

<a href="http://www.php.net/round" target="_blank">http://www.php.net/round</a>

Boofo 05-26-2003 08:45 PM

I tried that, too. When I round 2,174,891, I get 2 MB. This is how I used round:

PHP Code:

$attachs['MBbytes'] = round($attachs['MBbytes']); 


filburt1 05-26-2003 09:00 PM

Then:
[sql]
...SUM(LENGTH(attachment.filedata)) / 1024 * 1024 * 1024 AS mbytesum...
[/sql]
...then round it. :)

Boofo 05-26-2003 09:11 PM

That threw it way off. ;) Here's the code I am working with if that will help.

PHP Code:

/** Count of Attachments Per Forum and Bytes **/
$attachs=$DB_site->query_first("SELECT forum.title AS forum, COUNT(attachment.attachmentid) AS count, SUM(LENGTH(attachment.filedata)) AS bytes, SUM(LENGTH(attachment.filedata))/1024 AS KBbytes, SUM(LENGTH(attachment.filedata))/1048576 AS MBbytes
FROM attachment,post,thread,forum
WHERE attachment.attachmentid = post.attachmentid
AND post.threadid=thread.threadid
AND forum.forumid=thread.forumid
AND forum.forumid=
$forumid
GROUP BY thread.forumid
ORDER BY count DESC"
);

$attachs['count'] = number_format($attachs['count']);
$attachs['bytes'] = number_format($attachs['bytes']);
$attachs['KBbytes'] = number_format($attachs['KBbytes']);
$attachs['MBbytes'] = number_format($attachs['MBbytes']);
$attachs['MBbytes'] = round($attachs['MBbytes']);
If (
$attachs['MBbytes']<1) {
$attachs['MBbytes']='';
} else {
$attachs['MBbytes']="=" .$attachs['MBbytes']. "MB";
}
If (
$attachs['count'] !="0") {
$attachinfo="<tr>
        <td nowrap><smallfont><b>Total Attachments:</b> 
$attachs[count]</smallfont></td>
        <td nowrap><smallfont><b>Total Attachments Bytes:</b> 
$attachs[bytes] bytes ($attachs[KBbytes] KB$attachs[MBbytes])</smallfont></td>
</tr>"
;
} else {
$attachinfo="";
}
/** Count of Attachments Per Forum and Bytes **/ 


noppid 05-26-2003 11:00 PM

Use the php modulus operator to work with the remainder.

http://us3.php.net/manual/en/languag...arithmetic.php

Boofo 05-26-2003 11:17 PM

LOL I just tried that and I was way off. All I am trying to do is go 2 decimal places with the MB and have it rouind up if it needs to.

filburt1 05-26-2003 11:23 PM

Okay, get the sum in bytes, and assume it's in the $bytes variable.
PHP Code:

$megabytes $bytes / (1024 1024);
$megabytes number_format($megabytes2); // add commas and only 2 dec places 



All times are GMT. The time now is 12:55 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01210 seconds
  • Memory Usage 1,752KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete