Forum Moderators: coopster
Any help appreciated:
if (($responseqty>0) && ($responsesum>0))
{$responseavg=($responsesum/$responseqty);}
else {$responseavg=0;}
I have also tried:
$responseavg=@($responsesum/$responseqty);
Thanks,
Matt
Try this :)
Visit <snip> for more useful PHP scripts
[edited by: dreamcatcher at 7:07 am (utc) on Oct. 28, 2009]
[edit reason] No self promotion. See TOS. [/edit]
if (($responseqty>0 ¦¦ $responseqty = NULL) && ($responsesum>0 ¦¦ $responsesum = NULL))
With the single =, you are setting the values of $responseqty and $responsesum, and with the logical "or", it doesn't matter what the first conditional is, it will always return true.
if (($responseqty>0 ¦¦ $responseqty == NULL) && ($responsesum>0 ¦¦ $responsesum == NULL))
Even if this worked, it's going to try to divide by NULL. Huh? :-)
Null should never be greater than 0 anyway, but see L.I.A.'s recommendation, and again, what does it echo prior to your "if?"
The correct answer of fixing the problem for this issue came from
Zipper
Because the original code was fine. Most likely just needed to reupload the code after the fix that they posted.
//Fix just check quanity
if ($responseqty>0)
{
$responseavg=($responsesum/$responseqty);
}
else {$responseavg=0;
}
//Fix by checking both varaiable
if ($responseqty>0 && $responsesum>0)
{
$responseavg=($responsesum/$responseqty);
}
else {$responseavg=0;
}
//original code that works
if (($responseqty>0) && ($responsesum>0))
{$responseavg=($responsesum/$responseqty);}
else {$responseavg=0;}
//Fix to account for is LIA issue of null is true
if (($responseqty>0 && $responseqty != NULL) && ($responsesum>0 && $responsesum != NULL))
{
$responseavg=($responsesum/$responseqty);
}
else {
$responseavg=0;
}