2011-01-31 71 views
0

我正在建立一個網絡,其中有一個遊戲。網絡檢查在遊戲中,幫助它的邏輯

該遊戲是關於獲得點在網絡上查找某些信息。
當用戶找到一個令牌,一條信息,進行檢查,並且他/她得到該檢查的積分。

這裏是到目前爲止,我已經建立了數據庫:

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

回答

0

是否該checkings用戶checkings錶店發現?

在這種情況下,在授予用戶任何積分之前,請檢查該表。

如果不是,則爲用戶+檢查/令牌創建一個表,用於跟蹤用戶找到並授予的每個項目,並在用戶每次提交查找時搜索該表。

+0

非常感謝! – lleoun 2011-01-31 15:13:32