homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
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

 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?



 5:59 am on Apr 14, 2013 (gmt 0)

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


 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.


 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.


 11:22 pm on Apr 16, 2013 (gmt 0)

No, there's always at least 1 result.

Would if($divideby>0) work?


 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