Jump to content

[SOLVED] division by 0 error


sprint10s

Recommended Posts

below is the code that i wrote and it still works but i get a warning error on the site.  basically im trying to select all the rows in a racing event of in the case below the dash for cash race and take the results of the race and show an average start and a average finish of each event.  but if that user does not race in the dash and puts a 0 or null value i get the following error

Warning: Division by zero in /home/www/standridgemotorsports.com/func/db_results_body.php on line 105

 

i think i need another if statement to say if total is 0 then print 0 or something but not sure how to do it.

Thanks in advance.

 

//calculates average Dash Start

$ds = mysql_query("SELECT d_start FROM track WHERE user_id=1 ");

$numds = 0;

while($datads = mysql_fetch_array($ds)) {

if($datads['d_start']!=0 && $datads['d_start']!=""){

$numds++;  //This line is a shortcut that basically means $numhf=$numhf+1

}

 

$totalds += $datads['d_start'];

}

$avgds = round($totalds/ $numds, 2);

 

//end of Dash Start

Link to comment
https://forums.phpfreaks.com/topic/151824-solved-division-by-0-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.