어느부분이 잘못된건지 모르겠습니다

어느부분이 잘못된건지 모르겠습니다

QA

어느부분이 잘못된건지 모르겠습니다

본문


<?php
 
$sql = " SELECT * FROM g5_board_good WHERE mb_id='{$member['mb_id']}' AND bo_table='${$bo_table}' AND bg_flag='good' AND wr_id='$list[$i]['wr_id']' ";
$memberGood = sql_fetch($sql);
 
 
  if ($memberGood) {
    echo "<a href=\"".$good_href."\"  id=\"lt_good\" class=\"lt_v_good\">" . "<span class=\"lt_good\">" . " <i class=\"fa fa-heart\"></i><strong>{$list[$i]['wr_good']}</strong>". "</span>";        
    echo "<b class=\"lt_v_act_good\"></b>";
    echo "</a>";
    // 내가 좋아요를 눌렀을때 출력
  } else {
    echo "<a href=\"".$good_href."\"  id=\"lt_good\" class=\"lt_v_good\">" . "<span class=\"lt_good\">" . " <i class=\"fa fa-heart-o\"></i><strong>{$list[$i]['wr_good']}</strong>". "</span>";        
    echo "<b class=\"lt_v_act_nogood\"></b>";
   echo "</a>";
    // 내가 좋아요를 누르지 않았을때 출력
  }
 
?>
<!-- ---------------------------------------------------------------- -->

 
<?php }  ?>
 
<script>
$(function() {
    // 추천, 비추천
    $(".lt_v_good").click(function() {
        $tx = $(this).children(".lt_v_act_good");
 
 
        excute_good(this.href, $(this), $tx);
        return false;
    });
});
 
// $(function() {
//     // 추천, 비추천
//     $(".lt_v_good , .lt_v_nogood").click(function() {
 
//         if($memberGood){
//         $tx = $(this).children(".lt_v_act_good");
//         }
//         else{
//         $tx = $(this).children(".lt_v_act_nogood");
//         }
//         excute_good(this.href, $(this), $tx);
//         return false;
//     });
// });
 
</script>
 
<script>
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>
 

 

좋아요를누르면 하트가 아니면 흰색하트가 나오도록 하고싶은데 눌러도 숫자만 바뀌고 하트는 바뀌지 않습니다 어느부분이 잘못된건지 알려주세요!

991484400_1659670108.0936.png

이 질문에 댓글 쓰기 :

답변 2

if (data.count) {
    $el.find("strong").text(number_format(String(data.count)));
}

->

if (data.count) {
    $el.find("strong").text(number_format(String(data.count)));
    $el.find("i").removeClass('fa-heart-o').addClass('fa-heart');
}

로직상으로,

추천일 때
-> $el.find("i").removeClass('fa-heart-o').addClass('fa-heart');

취소일 때
-> $el.find("i").removeClass('fa-heart').addClass('fa-heart-o');

식으로 처리하면 됩니다.

코드상에서 '추천 취소' 부분이 어디인지.. 저는 찾지 못했습니다.

위의 php 조건문은 최초 페이지를 로딩할때만 작동됩니다.
좋아요 이벤트는 ajax로 이루어져있으니 ajax 응답값을 받아 처리하는 excute_good 함수에서도 별도의 처리를 해주셔야 합니다

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

회원로그인

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