homepage Welcome to WebmasterWorld Guest from 54.161.220.160
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP Warning: Division by zero
brokaddr



 
Msg#: 4564612 posted 1:44 am on Apr 14, 2013 (gmt 0)

This seems like such an easy to comprehend error message - however, when I view the page in question, I cannot replicate the error.

The error line trigger is as follows:
if( $i && (($i+1)%$divideby) == 0 ) {

Clearly I am missing an isset() or !== but I am not sure which/where to put it?

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4564612 posted 5:59 am on Apr 14, 2013 (gmt 0)

Obvious first question (in any language): what is the prior history of $divideby?

brokaddr



 
Msg#: 4564612 posted 9:44 pm on Apr 16, 2013 (gmt 0)

It's a mysql_num_rows call. I've tested that, and there is a number present.

swa66

WebmasterWorld Senior Member swa66 us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4564612 posted 10:59 pm on Apr 16, 2013 (gmt 0)

Any chance there's a query that doesn't return any rows ?

Calculating the remainder of something divided by zero isn't going to work out...
You should check that you get a $divideby that's different from zero before you calculate the modulo.

brokaddr



 
Msg#: 4564612 posted 11:22 pm on Apr 16, 2013 (gmt 0)

No, there's always at least 1 result.

Would if($divideby>0) work?

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 4564612 posted 4:08 pm on Apr 24, 2013 (gmt 0)

That should work, if $divideby is always an integer. Bear in mind that (N % 0.9) would also result in a divide by zero warning (the operands are first converted to integers).

Although if $divideby (the result of a SQL expression) should always be >= 1 then it looks as if something earlier in your code is failing.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved