supermanohar Posted October 14, 2014 Share Posted October 14, 2014 I am getting Warning: Division by zero in /rate.php on line 64 <?php function rateinstar($value) { preg_match_all('#([0-9]+)([0.0-9.9]+)|([0-9]+)#',$value,$tek); if($tek[0][1] > 0) { $rate=$tek[0][0]/$tek[0][1]; } else { $rate=0; } preg_match_all('#([0-9]+).([0-9]+)#',round($rate,1),$decm); if($decm[2][0] != "") { $no=($decm[1][0]*2)+1; for($i=1;$i<=10;$i++) { if($i<=$no){ if($i%2!=0) echo '<span class="starin piece1"></span>'; else echo '<span class="starin piece2"></span>'; }else{ if($i%2!=0) echo '<span class="starin piece3"></span>'; else echo '<span class="starin piece4"></span>'; } } }else{ for($i=1;$i<=10;$i++) { if($i<=$rate*2){ if($i%2!=0) echo '<span class="starin piece1"></span>'; else echo '<span class="starin piece2"></span>'; }else{ if($i%2!=0) echo '<span class="starin piece3"></span>'; else echo '<span class="starin piece4"></span>'; } } } } function rateintext($value) { preg_match_all('#([0-9]+)([0.0-9.9]+)|([0-9]+)#',$value,$tek); $rate=$tek[0][0]/$tek[0][1]; preg_match_all('#([0-9]+).([0-9]+)#',round($rate,1),$decm); return round($rate,1); } ?> Link to comment https://forums.phpfreaks.com/topic/291613-warning-division-by-zero-in-ratephp-on-line-64/ Share on other sites More sharing options...
Barand Posted October 14, 2014 Share Posted October 14, 2014 Rule of mathematics - you cannot divide by by zero. Check the value is not zero before attempting to divide by it. The error message is quite straight forward. Link to comment https://forums.phpfreaks.com/topic/291613-warning-division-by-zero-in-ratephp-on-line-64/#findComment-1493500 Share on other sites More sharing options...
ginerjm Posted October 14, 2014 Share Posted October 14, 2014 What do you want US to do about it? You didn't even show us the line that is giving you the error. Link to comment https://forums.phpfreaks.com/topic/291613-warning-division-by-zero-in-ratephp-on-line-64/#findComment-1493513 Share on other sites More sharing options...
supermanohar Posted October 15, 2014 Author Share Posted October 15, 2014 line nuber 64 $rate=$tek[0][0]/$tek[0][1]; you can check this error by clicking this url http://androing.com/download/com.littlefatfish.photo/Photo%20Gallery%20%28Fish%20Bowl%29 I don't have enough knowledge of php. Link to comment https://forums.phpfreaks.com/topic/291613-warning-division-by-zero-in-ratephp-on-line-64/#findComment-1493568 Share on other sites More sharing options...
codefossa Posted October 15, 2014 Share Posted October 15, 2014 You could do something like this to set the rate to 0 if it's going to attempt to divide by 0. $rate = $tek[0][1] != 0 ? $tek[0][0] / $tek[0][1] : 0; But, you may wish to just return 0 if it's not going to work. if ($tek[0][1] == 0) return 0;$rate = $tek[0][0] / $tek[0][1]; Link to comment https://forums.phpfreaks.com/topic/291613-warning-division-by-zero-in-ratephp-on-line-64/#findComment-1493576 Share on other sites More sharing options...
supermanohar Posted October 15, 2014 Author Share Posted October 15, 2014 thaks to Xaotique and all friends to help. It works http://androing.com Link to comment https://forums.phpfreaks.com/topic/291613-warning-division-by-zero-in-ratephp-on-line-64/#findComment-1493598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.