Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 游戏中的网页检查,帮助了解它的逻辑_Php_Mysql_Logic - Fatal编程技术网

Php 游戏中的网页检查,帮助了解它的逻辑

Php 游戏中的网页检查,帮助了解它的逻辑,php,mysql,logic,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 AU

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

该游戏旨在通过在网络上查找特定信息获得积分。
当用户找到一个令牌(一条信息)时,他/她会进行检查,并获得该检查的分数

以下是我迄今为止建立的数据库:

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

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

在这种情况下,在给用户任何分数之前,先检查该表

如果没有,则为用户+支票/代币创建一个表,该表跟踪用户找到并获得的每个项目,并在用户每次提交查找时搜索该表