Division by zero in....on line 140
Posted: Thu Jan 22, 2015 5:23 am
$additional = $row_rsPayment['payment_amount_paid'] / $row_rsPayment['rental_price'];
is on that line
any ideas?
is on that line
any ideas?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
so this needs to have a value other than 0 or NULL?Celauran wrote:Pretty clear. $row_rsPayment['rental_price'] is 0 or null.
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.
is there a way i can ignore any 0 or nulls?Celauran wrote:Yes. You can't divide by zero.
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 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;
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 >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 >