View Full Version : Do you see any errors in this code?
Prince
07-10-2002, 07:36 PM
** the reason I ask is because at 75% it is supposed to display a red image, but it conitnues to display yellow past 75.
$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:
$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:
$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:
$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 :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.