vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   percentage code is way off on large boards (https://vborg.vbsupport.ru/showthread.php?t=63062)

Boofo 03-28-2004 12:31 PM

percentage code is way off on large boards
 
Can anyone plaese tell me what I am doing wrong in the following code that would cause larger boards with high post and thread counts to display these percentages really far off?

PHP Code:

$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 1002) . '%';

$statscache['topthreadspercent'] = vb_number_format(($topstarter['count'] / $getthreadviews['count']) * 1002) . '%'

On my smaller board they are very accurate. But on a larger board they seem to be showing up like the following:

15,300 Posts (15,300.00%)

I have tried different variations of this and they all turn out the same.

assassingod 03-28-2004 12:42 PM

Don't know if this'll work or not, but try dividing by a hundred (or 10 or 1000):
PHP Code:

if($stats['activepercent'] > 100)
{
$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 100 1000) . '%'
}
else
{
 
$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 1002) . '%';



Boofo 03-28-2004 12:46 PM

Thanks. Steve. I'll have someone with a large board test this and get back to you here with the results. ;)

Boofo 03-28-2004 12:57 PM

Steve, do you know how to take the last 2 zeros after the decimal point off on a whole percent? Like if it is 50.00%, how would you make it so it showed up as 50%, but ONLY on whole percentages? If it is like 50.05%, I want that to show up.

AN-net 03-28-2004 04:24 PM

you could round it;)

Boofo 03-28-2004 04:56 PM

But that wouldn't leave it if it was 50.05%, would it? ;)

AN-net 03-28-2004 05:11 PM

you could creat some kind if statement:)

Boofo 03-28-2004 05:26 PM

Any examples? ;)

John 03-28-2004 09:11 PM

Quote:

Originally Posted by Boofo
Any examples? ;)

PHP Code:

// If you've got a percentage value like this:
$percentage 50.05;

// You can lob off the last two digits:
$lasttwo substr($percentage, -2);

// And then see if that equals 00
if ($lasttwo == '00')
{
     
// intval returns an integer value
     
$percentage intval($percentage);
}

// echo it out, you'll see that if $lasttwo == 00, it returns an int
echo $percentage

There's probably an infinitely more simple method of doing it, lol - but it works. :)

Boofo 03-28-2004 11:13 PM

As long as it works, that's all that really counts. Thank you, sir. ;)

Would you have any ideas on the percentage problems for bigger boards? )

EDIT: How would I incorporate this with this code?

PHP Code:

if($stats['activepercent'] > 100

$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 100 1000) . '%'

else 

$statscache['activepercent'] = vb_number_format(($numbermembers $newuserid) * 1002) . '%'



John 03-29-2004 08:52 AM

What does the $newuserid variable represent?

John 03-29-2004 09:02 AM

Either way - to figure out percentages, you divide the small number by the big number, and multiple by 100.

Looking at your code, I think you're doing it the other way round. (Presuming that $numbermembers is the total number, and $newuserid is the fraction of that.) If $newuserid is the bigger number, ignore the variable switch I made in the vb_number_format function below.

I've also removed the if statement, as I can't see what the difference is between the code in each branch.

PHP Code:


// this gives us a value in the $statscache['activepercent'] variable
$statscache['activepercent'] = vb_number_format(($newuserid $numbermembers) * 100); 

// You can lob off the last two digits: 
$lasttwo substr($statscache['activepercent'], -2); 

// And then see if that equals 00 
if ($lasttwo == '00'

     
// intval returns an integer value 
     
$statscache['activepercent']= intval($statscache['activepercent']); 


// if you want it in the variable, we can add the trailing % from before
$statscache['activepercent'] .= '%'


John 03-29-2004 09:03 AM

Also, instead of $newuserid, shouldn't it be $activemembers?

Boofo 03-29-2004 09:20 AM

Quote:

Originally Posted by John
Also, instead of $newuserid, shouldn't it be $activemembers?

When I used $activemembers like you suggested, it returned a 0. The $newuserid is the userid of the newest member, which would give you the highest number. ;)

I used this same code at one time and it seems that any boards that have over 1000 posts mess up with the percentage like this. It ends up showing like 15,300%. What would cause this to be happening? On my small site I don't have that problem. It works great for me.

John 03-29-2004 09:27 AM

What do you get with $numbermembers / $newuserid?

Boofo 03-29-2004 09:36 AM

I get this:

Quote:

Total Registrations: 46, Active Registrations: (42 Members = 91.30%)
That shows up fine but the problem I am having is with the Top Poster Percentage and the Top Thread Starter Percentage on larger boards. On mine, it works like it is suppposed to. On larger boards with large post counts and thread counts it really messes up. Check out my Forumhome Stats hack thread on the last 2 or 3 pages and you will see what I mean. Or even the first post in this thread.


All times are GMT. The time now is 03:03 PM.

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.01602 seconds
  • Memory Usage 1,768KB
  • 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
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (16)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete