Digiboy Posted March 13, 2013 Share Posted March 13, 2013 Hi guys, I have been scratching my head all day long to resolve error division by zero in code below: any thoughts? Thank you <ul> <?php echo "<script type='text/javascript' src='lib/js/jquery.min.js'></script> <script type='text/javascript' src='lib/jquery.raty.min.js'></script>"; $rating_cnt = 0; while($row = mysql_fetch_array($result)) { $bus_name=$row['name']; $bus_address_1=$row['address_1']; $bus_address_2=$row['address_2']; $bus_address_3=$row['address_3']; $bus_town=$row['town']; $bus_country=$row['country']; $bus_postcode=$row['potscode']; $bus_tel=$row['tel']; $bus_website=$row['website']; $bus_video=$row['video_link']; $bus_about=$row['about']; $select=mysql_query("SELECT * FROM towns WHERE id='$bus_town'"); while($myrow=mysql_fetch_array($select)) {$new_town=$myrow['town'];} /////// echo " <div class='business_list'> <div class='business-bars light-blue'><div class='business-bar-txt'>$bus_name, $new_town</div></div> <div class='business-row'> <div class='business-vimeo'><iframe src='http://player.vimeo.com/video/$bus_video' width='150' height='150' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></span></div> <div class='business-about'>$bus_about</div> </div> <div class='row2'> <div class='bus_vote'>"; $rating_cnt++; if(isset($_SESSION['account_no']) && $_SESSION['account_no']!='') { echo "<input type='hidden' id='prd_id_".$rating_cnt."' name='prd_id_".$rating_cnt."' value='".$myrow['prd_id']."' /> <div id='business_rate_".$rating_cnt."'></div> <script type='text/javascript'> $(function() { $.fn.raty.defaults.path = 'lib/img'; $('#business_rate_".$rating_cnt."').raty({ path : 'lib/img', cancel : false, cancelOff: 'cancel-off-big.png', cancelOn : 'cancel-on-big.png', half : false, size : 24, starHalf : 'star-half-big.png', starOff : 'star-off-big.png', starOn : 'star-on-big.png', click: function(score, evt) { var prd_id = $('#prd_id').val(); $.ajax({ type: 'POST', url: 'add_rate.php', data: { bid: prd_id, rating:score } }).done(function( msg ) { alert('You add rating on this business successfully.'); }); } }); }); </script>"; } else { $total_rate = 0; $rating_qry = "SELECT * FROM business_rating WHERE bid='".$myrow['prd_id']."'"; $rating_res = mysql_query($rating_qry) or die(mysql_error()); $count_rating = mysql_num_rows($rating_res); while($rating_row = mysql_fetch_array($rating_res)) { $total_rate += $rating_row['rate']; } $rating_score =round($total_rate/$count_rating); echo "<div id='business_rate_".$rating_cnt."'></div> <script type='text/javascript'> $(function() { $.fn.raty.defaults.path = 'lib/img'; $('#business_rate_".$rating_cnt."').raty({ path : 'lib/img', cancel : false, cancelOff: 'cancel-off-big.png', cancelOn : 'cancel-on-big.png', half : false, size : 24, readonly : true, score : ".$rating_score.", starHalf : 'star-half-big.png', starOff : 'star-off-big.png', starOn : 'star-on-big.png' }); }); </script>"; } ////////////////// echo" </div> <div class='bus_address'><div class='business-bar-txt'>$bus_address_1,$bus_address_2, $bus_address_1</div></div></div> </div> <div class='row3'> <div class='bus_reviews'></div><div class='bus_phone'></div><div class='bus_website'></div> </div> <!-- end of row --> "; } echo "<div class='results'>$total_pages Results</div>"; // pagination echo $paginate; ?> </ul> Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/ Share on other sites More sharing options...
timothyarden Posted March 13, 2013 Share Posted March 13, 2013 Just had a brief look over and I'm guessing its this line: $rating_score =round($total_rate/$count_rating);Ill have a quick look at the manual Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418326 Share on other sites More sharing options...
timothyarden Posted March 13, 2013 Share Posted March 13, 2013 It has to be that lineThats the only place you are really dividing regardless of the round function:$rating_score =round($total_rate/$count_rating);either the total_rate or count_rating must be zero hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418327 Share on other sites More sharing options...
haku Posted March 13, 2013 Share Posted March 13, 2013 $count_rating would be zero (it wouldn't be invalid if it $total_rate was zero - it's ok to divide zero, it's just not ok to divide by zero) Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418331 Share on other sites More sharing options...
timothyarden Posted March 13, 2013 Share Posted March 13, 2013 Might want to read what you posted a second time: "it's ok to divide zero, it's just not ok to divide by zero" Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418350 Share on other sites More sharing options...
AyKay47 Posted March 13, 2013 Share Posted March 13, 2013 Might want to read what you posted a second time: "it's ok to divide zero, it's just not ok to divide by zero" No, that statement is correct. Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418352 Share on other sites More sharing options...
Barand Posted March 13, 2013 Share Posted March 13, 2013 No, that statement is correct. In what way? Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418353 Share on other sites More sharing options...
AyKay47 Posted March 13, 2013 Share Posted March 13, 2013 (edited) Dividing 0 by anything is 0, dividing by zero is undefined/error? Edited March 13, 2013 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418357 Share on other sites More sharing options...
Barand Posted March 13, 2013 Share Posted March 13, 2013 Apologies, I completely misread the first half of the statement Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418364 Share on other sites More sharing options...
timothyarden Posted March 13, 2013 Share Posted March 13, 2013 Sorry your correct, when I was reading it late last night I read it as it's ok to divide by zero, it's just not ok to divide by zero not "it's ok to divide zero, it's just not ok to divide by zero" Quote Link to comment https://forums.phpfreaks.com/topic/275589-warning-division-by-zero-in/#findComment-1418490 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.