Division by zero 이거 없앨려면 어떻게 해야하나요? 방문자관련 소스입니다
본문
밑에 소스를 가지고 적용을 했는데 0이라 에러 뜨는거 같은데 어떻게 해야하나요?
Warning: Division by zero in /home/cwy/visit.skin.php on line 10
Compared with yesterday
<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
global $is_admin;
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
//Code By Day (http://dayever.me/)
add_stylesheet('<link rel="stylesheet" href="'.$visit_skin_url.'/style.css">', 0);
$graph1 = ($visit[1]/$visit[2])*100 ;
$graph = floor($graph1);
$last = 100-$graph;
?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script>
(function($) {
$.fn.counter = function(options) {
var settings = $.extend({
start: 0,
end: 100,
easing: 'swing',
duration: 400,
complete: ''
}, options);
var thisElement = $(this);
$({
count: settings.start
}).animate({
count: settings.end
}, {
duration: settings.duration,
easing: settings.easing,
step: function() {
var mathCount = Math.ceil(this.count);
thisElement.text(mathCount);
},
complete: settings.complete
});
};
}(jQuery));
$(document).ready(function() {
$('.score-graph').each(function() {
$(this).find('.score-graph-bar').animate({
width: $(this).attr('data-percent')
}, 2300);
});
});
</script>
<!-- 접속자집계 시작 { -->
<div class="maint">
<div id="score-counter" class="total-score"><?php echo $visit[1];?></div>
<div class="score-range">Compared with yesterday</div>
<div class="score-graph" data-percent="<?php echo $last;?>%">
<div class="score-graph-bar">
<span><i class="fa fa-star" aria-hidden="true"></i></span>
</div>
</div>
<!-- ./score-graph-->
<style>
.score-graph:after {
content: '<?php echo $visit[2];?>';
}
</style>
</div>
답변 1
$graph1 = ($visit[1]/$visit[2])*100 ;
을 이렇게 바꾸시면 되지 않을까요?
$graph1 = 0
if ( visit[2] != 0 ) $graph1 = ($visit[1]/$visit[2])*100 ;
답변을 작성하시기 전에 로그인 해주세요.