【小(xiǎo)編推薦】視(shì)頻(pín)網站(zhàn)中常>♠Ω€用(yòng)的(de)關注和(hé)取消關注(aj↑©ax+thinkphp+mysql)實現(xiàn)

2016-07-30   |&♣ ∏₩nbsp;  發布者:梁‌±國(guó)芳  &nbφ↔sp;|   ₩>§÷查看(kàn):3320次

php
 這(zhè)個(gè)是(shì)html內(nèi☆★₩α)容 css樣式就(jiù)不(bù)貼了(le)

如(rú)果已關注就(jiù)顯示實心桃心  否則 顯示虛心桃心
QQ截圖20160730181440QQ截圖20160730181449
<a class="guan" href×≤="javascript:;">
    <if condition="$gu'">γ€π§;
      <b cla≈ ™♥ss="guanzhu_down✘₽×÷"></b>
   <else />
     &♦×$∑lt;b class="guanzhu_start"‍•;></b>
</if>  &nbs®↕p;         &n  <∑bsp;     &n₽β♦←bsp;
    <span>關注<γΩ ♠;/span>
</a>

這(zhè)個(gè)是(shì)js部分α↕€↓(fēn)
    獲取關注人(rén)數(shù)的(de)∏£✘內(nèi)容,字符串轉換整型,獲得(de)當α¶₩Ω前關注人(rén)數(shù)
    tot=$('.↕©tot').html();
    tot=pars♦↔'eInt(tot);
    var x;
 $('.guan').click(function(){
 
        &nbs↓≈₽p;  //獲取當前關注标簽的(de)class ,判斷以✔γ後分(fēn)别關注跟取消關注
      >∏§β     //我這(zhè​​£)個(gè)是(shì)一(yī)個(gè)課程網站(zhàn)的(de)♥₹↔關注 需要(yào)攜帶課程id
        ‌≥     xx=$(thisλ♥÷).find('b').attr('class');
         <©π<;   //未關注則進行(xíng)關注
         ∑α";   if(xx=='guanzhu_startαλ←•'){
      &nb≈§£ sp;         $.‍¶post("{:U('guan')}",&★♥{'courseid':courseid},function(r){
      &nb€∏δ∞sp;         &n&₩₹bsp;   根據後面的(de)php函♣•數(shù)function guan()操作(zuò)數(shù'★¶∞)據庫,當關注成功是(shì)返回1;前台獲取到(dào)1以後給當前關注©₩÷¥人(rén)數(shù)加1;
          &nbs≥Ωαp;         if(↔®r==1){
        ≈±$       ←♥  ;      £•   if(x){
        &nbδ">sp;       &nb"✔§βsp;          ←​ $('.tot').html((x+1)+&qu<> ot;人(rén)");
        &nb₹™♣®sp;       > ±≠          &nbsγ≥p; 
          &nb♥✔sp;      ≥γ;     &nbsε‍•♠p;     x=x+1₹​;
        ↓§≥          &nbs φp;     }else{
      &≤≠₩αnbsp;     ♣λ₩₩         $♠$→;       $('.tot').html >↓((tot+1)+"人(rén)");
        ∏×↔÷       ™§;        ±★     
          &nb™✘sp;          ♣≈'€;       x=tot+1;
      &nb$"sp;     &nbλΩ↑sp;          ®> Ω;    
          α∞≠        &nbsπ®'p;     }
        &nb<δ✘±sp;       &​‌nbsp;     &n×ε÷≥bsp; 
         ×β       §€&    }
          &nbs​↔p;     });
        &¥¥Ωnbsp;  //已關注就(j'"iù)取消關注
     ×‍     根據後面的(de)php函數(''₩shù)function qu()操作(zuò)數(shù)據庫§☆,當取消關注成功是(shì)返回1;前台獲取 >ε®到(dào)1以後給當前關注人(rén)數(shù)減1;
         ★δ$   }else if(xx==↑®®₩'guanzhu_down'){
     "←≥∑           ¥ ↔$.post("{:U('qu')}"≤→§;,{'courseid':courseid},function(r)™&{
        &nbsΩ¥☆•p;          ±♥‍ if(r==1){
          &"      &nbs≠♣≥≥p;       if(x){≈​π÷
         λ♦₩∏;         ​;         &n♣♥★bsp; $('.tot').html((x-1¶γ₹)+"人(rén)");
  
        &n↑"£bsp;     &n®φbsp;         ₩☆∑    x=x-1;
      &nbs•απΩp;           &©&nbsp;     }else{
        &nbs¥€p;        Ω←₹       &¥ ¥nbsp;   $('.tot₽♠').html((tot-1)+&quo"¥>t;人(rén)");
       ↕π ;         ≥>π        δ≤™♣   
       <♠;         £εδ∏      &×≈nbsp;     x=tot &-1;
         £✔         &nb‌±★¶sp;       &σ><γnbsp;
     π←       &nbs≠☆p;       &nb←‌¶sp;   }
        &n§ ≠bsp;          ₽®;     
 
        &₽↕$nbsp;     ε®       ₹±}
          &n £↕§bsp; )};
 
 public function guan(){
       σ≥πφ $courseid=$_POST['courseid'];/∏'/從(cóng)前台獲取的(de)課程id
         '$userid=$_SESSION['userid'];≤>//$_SESSION中獲取用(yòng)戶id
        ελ$time=time();
       δ≥  $obj=M();
        增加關注
      ‌↑   $sql="insert into weixin_​↓<↑follow (userid,courseid,t←σαime) values('$userid',≈→↕ '$courseid','$time')";
      >'δ÷  $row=$obj->execute>α($sql);
       ♠±  if($row){
       查詢原來β₩↓÷(lái)課程關注數(shù)并加一(yī)
          &↔>nbsp; $sql1="selec focuse fromε< weixin_course_class wher cid='$cours γeid'";
          &λ nbsp; $focuse=$obj->query($sql1←± );
          ε >★  $focuse=$focuse[0][foc±×use];
      &nbπ¥≈sp;     $t©≈$βot=$focuse+1;
     £♦÷       $sql2="Ωλ;updat weixin_course_class set f✘¥<πocuse='$tot' wher cid='$courseid'&₩•quot;;
      &nbs∏↕♦p;     $ftot=$obj->execu∏↕te($sql2);
          >♦  echo 1;
        }
    }
    public function qu(){
     £∏<   
        &≠  ;$courseid=$_POST['courseid'];//從(cóng)§♣前台獲取的(de)課程id
        $user↕♦∑×id=$_SESSION['userid'];//$_SE×ΩSSION中獲取用(yòng)戶id
        $obj=M();‍"" 
       ₩α€♠取消增加關注
      γ₹≠£  $sql="delet from &nbs©∑©Ωp;weixin_follow wher userid='$userid' a±✘✘₩nd courseid='$courseid'";
        $row=$o>↓ §bj->execute($sql);
         i$∞α$f($row){
        &nbs↕α®αp;查詢原來(lái)課程關注數(shù)&δ并減一(yī)
      &n'​bsp;     $sql1="selec fo≤$δ¶cuse from weixin_course_cl ∞ass wher cid='$courseid'∏♠∑";
          &n★¥<δbsp; $focuse=$obj->q↕≤∏αuery($sql1);
          &n☆'bsp; $focuse=$focuse[0][focuse£<₩∑];
      &nbs×¶✔£p;     $tot=$focuse× -1;
        β     $sql2=&quoγ↑ ∏t;updat weixin_course_class set £≥‌​focuse='$tot' wher ci ≤d='$courseid'";
      &nb'•sp;     $ftot=$★$obj->execute($sql​'♠2);
        &nbs​∞→p;   echo 1;
        }
    }