开发者

Web checking in game, help with the logic of it

I'm building a web which has a game in it.

The game is about getting points for finding certain information in the web.

When the user finds a token, a piece of information, does a checking and he/she gets points for that checking.

Here's the database I've built so far:

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 ;

And her开发者_JAVA百科e's my code.

The problem with it is: how do I know if the points have been given already for that token? Please help me with the logic, I've lost my scope and I cannot see the way to do it. I have probably started coding in the wrong direction. I explain what I'm trying to do within the code.

Thanks very much

<?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." ";}
     ?> 


Does the checkings table store which checkings the user has found?

In that case, serach that table before awarding the user any points.

If not, create a table for user + checkings/tokens that keep track on each item the user has found and been awarded and search that table every time the user submits a find.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜