Welcome to WebmasterWorld Guest from 23.22.250.113

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Warning: Division by zero

     

brokaddr

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

5+ Year Member



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

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

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



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

brokaddr

9:44 pm on Apr 16, 2013 (gmt 0)

5+ Year Member



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

swa66

10:59 pm on Apr 16, 2013 (gmt 0)

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



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

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

5+ Year Member



No, there's always at least 1 result.

Would if($divideby>0) work?

penders

4:08 pm on Apr 24, 2013 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month