Advertisement
zulmi

liked function

Dec 16th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. public function actionLiked(){
  2.          $ipaddress=$_SERVER['REMOTE_ADDR'];
  3.          $storyid=$_POST['storyid'];
  4.  
  5.          $SQL="SELECT * FROM tutorial_approved where id='$storyid'";
  6.          $commands=Yii::app()->db->createCommand($SQL);
  7.          $result=$commands->queryRow();
  8.  
  9.          $sql = "SELECT * FROM likes WHERE approved_id='$storyid' AND ip='".$ipaddress."'";
  10.          $query = Yii::app()->db->createCommand($sql);
  11.          $data=$query->queryScalar();
  12.          
  13.          if ($data[0]==null) {       
  14.          if ($result['likes']==0 || $result['likes']==NULL) {
  15.  
  16.             $SQL1="update tutorial_approved set likes=1 where id='$storyid'";
  17.             $command= Yii::app()->db->createCommand($SQL1);
  18.             $n1=$command->execute();
  19.  
  20.          }else{
  21.  
  22.             $SQL2="update tutorial_approved set likes=likes+1 where id='$storyid'";
  23.             $command= Yii::app()->db->createCommand($SQL2);
  24.             $n2=$command->execute();
  25.  
  26.          }
  27.  
  28.             $SQL3="insert into likes values('','$storyid','".$ipaddress."') ";
  29.             $command= Yii::app()->db->createCommand($SQL3);
  30.             $n3=$command->execute();
  31.  
  32.  
  33.         }else{
  34.             $SQL4="DELETE FROM likes where approved_id='$storyid' and ip='".$ipaddress."' ";
  35.             $command= Yii::app()->db->createCommand($SQL4);
  36.             $n4=$command->execute();
  37.  
  38.             $SQL5="update tutorial_approved set likes=likes-1 where id='$storyid'";
  39.             $command= Yii::app()->db->createCommand($SQL5);
  40.             $n5=$command->execute();
  41.         }
  42.  
  43.         $SQL="SELECT * FROM tutorial_approved where id='$storyid'";
  44.         $commands=Yii::app()->db->createCommand($SQL);
  45.         $reslt=$commands->queryRow();
  46.  
  47.         echo $reslt['likes'] ;
  48.  
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement