网络检查游戏,帮助它的逻辑

时间:2011-01-31 11:35:35

标签: php mysql logic

我正在建立一个有游戏的网站。

游戏的目的是获取在网络上查找某些信息的要点 当用户找到一个令牌,一条信息,进行检查并且他/她获得该检查的积分。

这是我到目前为止建立的数据库:

CREATE TABLE IF NOT EXISTS `user` (
  `userid` int(11) NOT NULL AUTO_INCREMENT,
  `points` int(11) NOT NULL,
  PRIMARY KEY (`userid`)
) ENGINE=MyISAM  DEFAULT AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `checkings` (
  `checkingsid` int(11) NOT NULL AUTO_INCREMENT,
   `userid` int(11) NOT NULL,
  `tokensid` int(11) NOT NULL,  
   `checked` int(11) NOT NULL,
  PRIMARY KEY (`checkingsid`)
) ENGINE=MyISAM  DEFAULT AUTO_INCREMENT=1 ;


CREATE TABLE IF NOT EXISTS `tokens` (
  `tid` int(11) NOT NULL AUTO_INCREMENT,
  `tokensid` int(11) NOT NULL,
   `name` varchar(255) NOT NULL,
   `points` int(11) NOT NULL,
  PRIMARY KEY (`tid`)
) ENGINE=MyISAM  DEFAULT AUTO_INCREMENT=1 ;

这是我的代码。

它的问题是:我如何知道是否已经为该令牌提供了积分? 请帮我逻辑,我已经失去了我的范围,我看不到这样做的方法。我可能开始编写错误的方向。 我解释了我在代码中要做的事情。

非常感谢

<?php  
                //connected to database and obtained $userId and $tokenID already
              $query0 = "select * from checkings where userid=".$userId." and tokensid=".$tokenId."";
              $result0 = mysql_query($query0);
              $row0 = mysql_fetch_array($result0); 

               if (($row0['checked']!=' ')|| ($row0['checked']!='0')){ // if checked is empty or 0 the user didn't do the checking in this token yet

                  if (($row0['checked']==1)&&($row0['userid']==$userId)&&($row0['tokensid']==$tokenId) ){//the checking has already been inserted

                      //how many points are given for checking in this token? 
                      $query2 = "select points from tokens where tokensid='".$tokenId."'";
                      $result2 = mysql_query($query2);  
                      $row2 = mysql_fetch_array($result2);
                      $pointstoken = $row2['points']; 

                       //How many points have the user? 
                      $query3 = "select points from user where userid='".$userId."'";
                      $result3 = mysql_query($query3);  
                      $row3 = mysql_fetch_array($result3);
                      $pointsUser = $row3['points'];  

                      //user points are updated after checking in this token 
                      $pointsTotal = $pointsUser+$pointstoken;  
                      $query4 = "update user set points=".$pointsTotal." where userid=".$userId." ";
                      $result4 = mysql_query($query4);  



                    }else{//here I do the checking in the token inseting the ids plus a 1 as for checked 
                      $query1 = "insert into checkings (userid, tokensid,checked ) values (".$userId.",".$tokenId.",1)";
                      $result1 = mysql_query($query1);


                  }   

               }else{ echo "Hi, user ".$userId." you've already done the checking in token id ".$tokenId." ";}
     ?> 

1 个答案:

答案 0 :(得分:0)

检查表是否存储了用户找到的检查?

在这种情况下,在授予用户任何积分之前先搜索该表。

如果没有,请为用户+检查/令牌创建一个表,跟踪用户找到并获得的每个项目,并在每次用户提交查找时搜索该表。