Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.