Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionLiked(){
- $ipaddress=$_SERVER['REMOTE_ADDR'];
- $storyid=$_POST['storyid'];
- $SQL="SELECT * FROM tutorial_approved where id='$storyid'";
- $commands=Yii::app()->db->createCommand($SQL);
- $result=$commands->queryRow();
- $sql = "SELECT * FROM likes WHERE approved_id='$storyid' AND ip='".$ipaddress."'";
- $query = Yii::app()->db->createCommand($sql);
- $data=$query->queryScalar();
- if ($data[0]==null) {
- if ($result['likes']==0 || $result['likes']==NULL) {
- $SQL1="update tutorial_approved set likes=1 where id='$storyid'";
- $command= Yii::app()->db->createCommand($SQL1);
- $n1=$command->execute();
- }else{
- $SQL2="update tutorial_approved set likes=likes+1 where id='$storyid'";
- $command= Yii::app()->db->createCommand($SQL2);
- $n2=$command->execute();
- }
- $SQL3="insert into likes values('','$storyid','".$ipaddress."') ";
- $command= Yii::app()->db->createCommand($SQL3);
- $n3=$command->execute();
- }else{
- $SQL4="DELETE FROM likes where approved_id='$storyid' and ip='".$ipaddress."' ";
- $command= Yii::app()->db->createCommand($SQL4);
- $n4=$command->execute();
- $SQL5="update tutorial_approved set likes=likes-1 where id='$storyid'";
- $command= Yii::app()->db->createCommand($SQL5);
- $n5=$command->execute();
- }
- $SQL="SELECT * FROM tutorial_approved where id='$storyid'";
- $commands=Yii::app()->db->createCommand($SQL);
- $reslt=$commands->queryRow();
- echo $reslt['likes'] ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement