suppress errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nikko50
Forum Commoner
Posts: 43
Joined: Thu Apr 08, 2004 6:28 am

suppress errors

Post by nikko50 »

Hello. I'm getting warning division by zero messages with the below statement.

$average=$getcostline2[totalsum]/$getcostline[receivedsum];

Can I suppress these error messages with the @ control operator. If yes please show me how. Thanks so much.
Tracy:)
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Well it's either because your total values equal 0 or they are not running anything at all. What happens when you print out the variables?.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

div by zero is usually bad to ignore, at any level. I'd make sure 'receivedsum' is correct and non-zero..
nikko50
Forum Commoner
Posts: 43
Joined: Thu Apr 08, 2004 6:28 am

Post by nikko50 »

Hi guys:) I'm pulling monthly inventory results so sometimes there will be no received sum along with no totalcost sum. How can I go about supressing those division by zero messages?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

by not doing the math if it's zero received..
nikko50
Forum Commoner
Posts: 43
Joined: Thu Apr 08, 2004 6:28 am

Post by nikko50 »

simple enough. Will do that.
nikko50
Forum Commoner
Posts: 43
Joined: Thu Apr 08, 2004 6:28 am

Post by nikko50 »

Hey boys:)
Does this look good to you or how would you write it???

if($getcostline[receivedsum]=='0'){
$average='0';}
else{
$average=$getcostline2[totalsum]/$getcostline[receivedsum];
$average=round($average,2);
}
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

I would probably use:

Code: Select all

if($getcostlineїreceivedsum] != 0)
{
 $average=$getcostline2їtotalsum]/$getcostlineїreceivedsum]; 
 $average=round($average,2);
}
What values did you get when you printed those variables to the screen?.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remember to always, always quote string array indices.

and please start using

Code: Select all

tags.

wouldn't the average actually be x / total ?
nikko50
Forum Commoner
Posts: 43
Joined: Thu Apr 08, 2004 6:28 am

Post by nikko50 »

Hey Joe. Code works great. Thanks for all your help. If you can think of anything else let me know.
Tracy:)
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

No problem.

8)
Post Reply