vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Do you see any errors in this code? (https://vborg.vbsupport.ru/showthread.php?t=40905)

Prince 07-10-2002 07:36 PM

Do you see any errors in this code?
 
** the reason I ask is because at 75% it is supposed to display a red image, but it conitnues to display yellow past 75.

PHP Code:

  $inboxpms=$DB_site->query_first("SELECT COUNT(*) AS messages FROM privatemessage WHERE userid=$bbuserinfo[userid] AND folderid=0 $ignoreusers");
  if (
$inboxpms 1) {
  
$pmpercent "1"// stop divisions by zero
  
} else {
  
$pmpercent round(($inboxpms[messages] / $pmquota) * 100,2);
  }
  if (
$pmpercent>50) {
  
$barimg="{imagesfolder}/yellow.gif";
  } elseif (
$pmpercent>75) {
  
$barimg="{imagesfolder}/red.gif";
  } else {
  
$barimg="{imagesfolder}/green.gif";
  } 


Xenon 07-10-2002 09:13 PM

yes i see a fault in your code so it is correct:
PHP Code:

$inboxpms=$DB_site->query_first("SELECT COUNT(*) AS messages FROM privatemessage WHERE userid=$bbuserinfo[userid] AND folderid=0 $ignoreusers");
  if (
$inboxpms 1) {
  
$pmpercent "1"// stop divisions by zero
  
} else {
  
$pmpercent round(($inboxpms[messages] / $pmquota) * 100,2);
  }
  if (
$pmpercent>50 && $pmpercent<=75) {
  
$barimg="https://vborg.vbsupport.ru/vbimages/yellow.gif";
  } elseif (
$pmpercent>75) {
  
$barimg="https://vborg.vbsupport.ru/vbimages/red.gif";
  } else {
  
$barimg="https://vborg.vbsupport.ru/vbimages/green.gif";
  } 

remember when something is higher than 75 ist also higher than 50 ;)

Prince 07-11-2002 12:03 AM

I see your logic there, but that screwed up the PM %. :confused:

Xenon 07-11-2002 07:53 AM

????

can't see a fault, can you explain a bit more?

Prince 07-11-2002 02:03 PM

The code tells how full the PM box is based on the max number of PM's allowed.
So, right now I have it set to a max of 75 PM's, and I have 60 PMs total in my PM box, so the % should read 86% full, but when I changed the code it made that % inaccurate, it said something like 40% full.

Xenon 07-11-2002 03:07 PM

perhaps you have 60 pms total, but just 30 pms in your inbox?
you just call pms in folderid=0 (inbox-folder) but no sent messages would be inside

Prince 07-11-2002 04:00 PM

this code is looking at all folders:

PHP Code:

 $inboxpms=$DB_site->query_first("SELECT COUNT(*) AS messages FROM privatemessage WHERE userid=$bbuserinfo[userid] $ignoreusers");
  if (
$inboxpms 1) {
  
$pmpercent "1"// stop divisions by zero
  
} else {
  
$pmpercent round(($inboxpms[messages] / $pmquota) * 100,2);
  }
  if (
$pmpercent>50) {
  
$barimg="{imagesfolder}/yellow.gif";
  } elseif (
$pmpercent>75) {
  
$barimg="{imagesfolder}/red.gif";
  } else {
  
$barimg="{imagesfolder}/green.gif";
  } 


Xenon 07-11-2002 04:06 PM

i'd really change the code to that:
PHP Code:

$inboxpms=$DB_site->query_first("SELECT COUNT(*) AS messages FROM privatemessage WHERE userid=$bbuserinfo[userid] $ignoreusers");
$pmpercent=round(($inboxpms[messages] / $pmquota) * 100,2);

  if (
$pmpercent>50 && $pmpercent<=76) {
  
$barimg="https://vborg.vbsupport.ru/vbimages/yellow.gif";
  } else if (
$pmpercent>75) {
  
$barimg="https://vborg.vbsupport.ru/vbimages/red.gif";
  } else {
  
$barimg="https://vborg.vbsupport.ru/vbimages/green.gif";
  } 

no division by zero is possible, because zero is devided by something else, not the other way round...

Prince 07-11-2002 04:17 PM

Perfect!

thanks Xenon :)

Xenon 07-11-2002 04:21 PM

np :)


All times are GMT. The time now is 12:28 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.01047 seconds
  • Memory Usage 1,751KB
  • 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
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)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