페이지 갯수 만큼 좋아요 이벤트 일어나는데 이유를 모르겠어요 도와주세요

페이지 갯수 만큼 좋아요 이벤트 일어나는데 이유를 모르겠어요 도와주세요

QA

페이지 갯수 만큼 좋아요 이벤트 일어나는데 이유를 모르겠어요 도와주세요

본문

991484400_1658929100.9915.png

 

latest.skin.php에 만들었는데 좋아요를 누르면 저렇게 숫자가 바로 바뀌고 했으면 좋겠는데 추천이 취소되었습니다라는 문장이랑 좋아요가 글이 올라는 갯수만큼 이벤트가 반복되서 어찌해야할지 모르겠습니다.


<?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 = 297;
$thumb_height = 212;
$list_count = (is_array($list) && $list) ? count($list) : 0;
?>
 
<div class="pic_li_lt">
   
<h2 class="lat_title"><a href="<?php echo get_pretty_url($bo_table); ?>"><?php echo $bo_subject ?></a></h2>
 
    <ul>
    <?php
    for ($i=0; $i<$list_count; $i++) {
       
        $img_link_html = '';
       
        $wr_href = get_pretty_url($bo_table, $list[$i]['wr_id']);
        //좋아요
        $good_href = G5_BBS_URL.'/good.php?bo_table='.$bo_table.'&wr_id='.$list[$i]['wr_id'].'&good=good';
        //싫어요
        $nogood_href = G5_BBS_URL.'/good.php?bo_table='.$bo_table.'&wr_id='.$list[$i]['wr_id'].'&good=nogood';
 
    ?>
   
        <li>
            <?php echo $img_link_html; ?>
            <?php
            if ($list[$i]['icon_secret']) echo "<i class=\"fa fa-lock\" aria-hidden=\"true\"></i><span class=\"sound_only\">비밀글</span> ";
 
            echo "<a href=\"".$wr_href."\" class=\"pic_li_tit\"> ";
           
            if ($list[$i]['ca_name']) {
                echo  "<span class =\"lt_ca\">" ."[{$list[$i]['ca_name']}]". "</span>";
            }
            // ------------------------------------
     
             //  ---------------------------------------------좋아요 구현 완료
            if ($list[$i]['is_notice'])
                echo "<strong>".$list[$i]['subject']."</strong>";
            else
                echo $list[$i]['subject'];
       
                    echo "</a>";
 
 
        ?>
 
            <div class="lt_info">
             <!-- <a href="<?php echo $good_href; ?>"><?php echo "<span class=\"lt_good\"><i class=\"fa fa-heart\"></i> ".$list[$i]['wr_good']."</span>"; ?></a> -->
   
            <span class="lt_v_act_gng">        
                <a href="<?php echo $good_href; ?>" id="lt_good" class="lt_v_good"><?php echo "<span class=\"lt_good\"><i class=\"fa fa-heart\"></i> </span>"; ?><strong><?php echo ($list[$i]['wr_good']) ?></strong></a>
                <b id="lt_v_act_good"></b>
            </span>

 
                 <!-- <a href="<?php echo $nogood_href; ?>"id="lt_nogood" class="lt_v_nogood"><?php echo "<span class=\"lt_good\"><i class=\"fa fa-heart-o\"></i> ".$list[$i]['wr_nogood']."</span>"; ?></a> -->
                 <!-- <?php echo "<span class=\"lt_cmt\"><i class=\"fa fa-comment-o\"></i>" .$list[$i]['wr_comment']."</span>"; ?>   -->
           
        </br>      
 

 
<script>
$(function() {
    // 추천, 비추천
    $("#lt_good").click(function() {
        var $tx;
        if(this.id == "lt_good")
            $tx = $("#lt_v_act_good");
 
        excute_good(this.href, $(this), $tx);
        return false;
    });
});
 
function excute_good(href, $el, $tx)
{
    $.post(
href,
        { js: "on" },
        function(data) {
if(data.error) {
alert(data.error);
                return false;
            }

 
if(data.count) {
    $el.find("strong").text(number_format(String(data.count)));
}
 
if(data.msg){
    $tx.stop().hide();
    $tx.text(data.msg);
    $tx.fadeIn(200).delay(2500).fadeOut(200);
}

 
        }, "json"
    );
}
</script>

 
    <?php }  ?>
    <?php if ($list_count == 0) { //게시물이 없을 때  ?>
    <li class="empty_li">게시물이 없습니다.</li>
    <?php }  ?>
    </ul>
    <!-- <a href="<?php echo get_pretty_url($bo_table); ?>" class="lt_more"><span class="sound_only"><?php echo $bo_subject ?></span>더보기</a> -->
 
</div>
</script>

 

이게 latest코드인데 어디가 문제인지 말씀만 해주시면 제가 고치고 싶어요 도와주세요!!

이 질문에 댓글 쓰기 :

답변 2

for문안에 id값이 반복되요.. id는 고유해야쥬...

스크립트도 list_count만큼 계속 만들어지구요

힌트는 여기까지~

 

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

회원로그인

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