Division by zero in....on line 140
Moderator: General Moderators
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Division by zero in....on line 140
$additional = $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'];
is on that line
any ideas?
is on that line
any ideas?
Re: Division by zero in....on line 140
Pretty clear. $row_rsPayment['rental_price'] is 0 or null.
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: Division by zero in....on line 140
so this needs to have a value other than 0 or NULL?Celauran wrote:Pretty clear. $row_rsPayment['rental_price'] is 0 or null.
Re: Division by zero in....on line 140
Yes. You can't divide by zero.
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: Division by zero in....on line 140
ok i thought all that column was populated with a figure rather that 0 so i need to checkCelauran wrote:Yes. You can't divide by zero.
thanks
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: Division by zero in....on line 140
is there a way i can ignore any 0 or nulls?Celauran wrote:Yes. You can't divide by zero.
Re: Division by zero in....on line 140
Code: Select all
$additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: Division by zero in....on line 140
code hinting is show something is incorrectCelauran wrote: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: Select all
$additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;
Re: Division by zero in....on line 140
Mine isn't. Runs in the console, too.jonnyfortis wrote:code hinting is show something is incorrectCelauran wrote: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: Select all
$additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;
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 >-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: Division by zero in....on line 140
i was missing a bracket.Celauran wrote:Mine isn't. Runs in the console, too.jonnyfortis wrote:code hinting is show something is incorrectCelauran wrote: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: Select all
$additional = (isset($row_rsPayment['rental_price']) && $row_rsPayment['rental_price'] != 0) ? $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'] : 0;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 >
thanks