메인에 평점(숫자)만 노출하고 싶은데 어려울까요?

메인에 평점(숫자)만 노출하고 싶은데 어려울까요?

QA

메인에 평점(숫자)만 노출하고 싶은데 어려울까요?

본문

결과값이 0.0으로 나오네요 게시물 평점은 8.7인데요..ㅜㅜ 

도와주세요

 

사용스킨은 https://sir.kr/g5_skin/10430 입니다.

 

 

 

코드

<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = (isset($options['thumb_w']) && $options['thumb_w'] > 0) ? $options['thumb_w'] : 235;
$thumb_height = (isset($options['thumb_h']) && $options['thumb_h'] > 0) ? $options['thumb_h'] : 149;
$list_count = (is_array($list) && $list) ? count($list) : 0;

 

$colspan = 5;

if ($is_checkbox) $colspan++;
if ($is_good) $colspan++;
if ($is_nogood) $colspan++;


?>

<style type="text/css">
#list_la { width:350px; padding:0; margin:0; line-height:25px; }
#list_la a { color:#666; text-decoration:none;}
#list_la a:hover { text-decoration:none;}
#list_la ul { list-style:none; padding:0; margin:0; }
#list_la li {  padding:0; margin:0; }
#list_la .subject { float:left; width:220px; }
#list_la .date { float:right; width:80px; }
#list_la .view { float:right; width:50px; }
</style>

        
<div id="list_la">


<?php
    for ($i=0; $i<$list_count; $i++) {
        $thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);

        if($thumb['src']) {
            $img = $thumb['src'];
        } else {
            $img = G5_IMG_URL.'/no_img.png';
            $thumb['alt'] = '이미지가 없습니다.';
        }
        $img_content = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
        $wr_href = get_pretty_url($bo_table, $list[$i]['wr_id']);

        if ($list[$i]['icon_new']) $icon_new = "<span class=\"new_icon\">N<span class=\"sound_only\">새글</span></span>";
        if ($list[$i]['icon_hot']) $icon_hot = "<span class=\"hot_icon\">H<span class=\"sound_only\">인기글</span></span>";

        $div_style = ($i!=0)?' style="display:none"':'';
?>


        

<style>
#popup_<?=$i?> { display:none; position:fixed; top:0; width:100%; height:100%; left:0; z-index:999999; overflow:hidden; }
#popup_<?=$i?> .guide { position:absolute; background:#fff; top:100px; left:50%; margin-left:-300px; width:600px; padding:5px; height:500px; border:2px solid #000; z-index:999; }
#popup_<?=$i?> .bg { position:fixed; top:0; left:0; width:100%; background:#000; height:100%; filter:alpha(opacity=90); opacity:0.9; -moz-opacity:0.9; z-index:888 }
#popup_<?=$i?> .close { position:absolute; top:-5px; right:-60px; }
#popup_<?=$i?> .con { margin:20px; height:450; overflow-x:hidden; overflow-y:auto;}
#popup_<?=$i?> .title { font-size:18px; }
</style>

            <ul>


                <li>

<div class="subject"><div id="pop_<?=$i?>" style="cursor:pointer">


<?php echo run_replace('thumb_image_tag', $img_content, $thumb); ?>
<?php echo cut_str(strip_tags($list[$i]['subject']), 20,'…'); ?><br>
평점

<?php
$row = sql_fetch(" select count(*) as cnt, sum(is_score) as total from {$g5['group']} where it_id = '{$it_id}' "); 

$average = ($row['total'] && $row['cnt']) ? $row['total'] / $row['cnt'] : 0;

?>
<?php echo number_format($average,1);?>

                    

</div></div>
                    


                </li>

                <!--레이어-->
                <div id="popup_<?=$i?>">
                    
                    <div class="guide">

                        <div class="close"><img src="<?=$latest_skin_url?>/img/close.png"></div>
    


                        <div class="con">
                            <span class="title"><?php echo cut_str(strip_tags($list[$i]['subject']), 50,'…'); ?></span><br><br>
                            <?=$list[$i]['wr_content'];?>
                        </div>

                    </div>

                    <div class="bg"></div>

                </div>
                <!--//레이어-->

            </ul>

<script>
$(document).ready(function(){
    $("#pop_<?=$i?>").click(function()
      {
        $("#popup_<?=$i?>").show();
      });
    $(".close").click(function()
      {
        $("#popup_<?=$i?>").hide();
      });

});
</script>


        <?php } ?>

</div>

이 질문에 댓글 쓰기 :

답변 1

https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html

단순히 평균을 구하는 거면

Average() 함수를 검토해 보세요

$row = sql_fetch(" select count(*) as cnt, sum(is_score) as total from {$g5['group']} where it_id = '{$it_id}' ");
그리고 여기서
 sql이 원하는 대로 나오는지
 Echo로 출력해서 확인해 보세요

답변을 작성하시기 전에 로그인 해주세요.
전체 123,127 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT