Welcome to WebmasterWorld Guest from 54.147.189.54

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Warning: Division by zero

     
1:44 am on Apr 14, 2013 (gmt 0)

Junior Member

5+ Year Member

joined:July 13, 2010
posts:170
votes: 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)

Senior Member from US 

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

joined:Apr 9, 2011
posts:12702
votes: 244


Obvious first question (in any language): what is the prior history of $divideby?
9:44 pm on Apr 16, 2013 (gmt 0)

Junior Member

5+ Year Member

joined:July 13, 2010
posts:170
votes: 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)

Senior Member

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

joined:Aug 7, 2003
posts:4783
votes: 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)

Junior Member

5+ Year Member

joined:July 13, 2010
posts:170
votes: 0


No, there's always at least 1 result.

Would if($divideby>0) work?
4:08 pm on Apr 24, 2013 (gmt 0)

Senior Member

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

joined:July 3, 2006
posts: 3123
votes: 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.