Page 1 of 1

Division by zero in....on line 140

Posted: Thu Jan 22, 2015 5:23 am
by jonnyfortis
$additional = $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'];

is on that line
any ideas?

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 6:02 am
by Celauran
Pretty clear. $row_rsPayment['rental_price'] is 0 or null.

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 6:12 am
by jonnyfortis
Celauran wrote:Pretty clear. $row_rsPayment['rental_price'] is 0 or null.
so this needs to have a value other than 0 or NULL?

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 6:25 am
by Celauran
Yes. You can't divide by zero.

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 6:32 am
by jonnyfortis
Celauran wrote:Yes. You can't divide by zero.
ok i thought all that column was populated with a figure rather that 0 so i need to check

thanks

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 7:00 am
by jonnyfortis
Celauran wrote:Yes. You can't divide by zero.
is there a way i can ignore any 0 or nulls?

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 7:08 am
by Celauran

Code: Select all

$additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;
That will set $additional to 0 is rental price is 0 or null, which will avoid the error. I don't know that this is necessarily the best solution, though, because I don't really have any information about what's going on beyond the one line you posted. Might make more sense to exclude such lines from the query altogether.

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 7:11 am
by jonnyfortis
Celauran wrote:

Code: Select all

$additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;
That will set $additional to 0 is rental price is 0 or null, which will avoid the error. I don't know that this is necessarily the best solution, though, because I don't really have any information about what's going on beyond the one line you posted. Might make more sense to exclude such lines from the query altogether.
code hinting is show something is incorrect

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 7:17 am
by Celauran
jonnyfortis wrote:
Celauran wrote:

Code: Select all

$additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;
That will set $additional to 0 is rental price is 0 or null, which will avoid the error. I don't know that this is necessarily the best solution, though, because I don't really have any information about what's going on beyond the one line you posted. Might make more sense to exclude such lines from the query altogether.
code hinting is show something is incorrect
Mine isn't. Runs in the console, too.

Code: Select all

[08:16 am] [~]
$ php -a
Interactive shell

php > $additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;
php > print_r($additional);
0
php >

Re: Division by zero in....on line 140

Posted: Thu Jan 22, 2015 7:22 am
by jonnyfortis
Celauran wrote:
jonnyfortis wrote:
Celauran wrote:

Code: Select all

$additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;
That will set $additional to 0 is rental price is 0 or null, which will avoid the error. I don't know that this is necessarily the best solution, though, because I don't really have any information about what's going on beyond the one line you posted. Might make more sense to exclude such lines from the query altogether.
code hinting is show something is incorrect
Mine isn't. Runs in the console, too.

Code: Select all

[08:16 am] [~]
$ php -a
Interactive shell

php > $additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;
php > print_r($additional);
0
php >
i was missing a bracket.
thanks