私はそこにゲームを持っているウェブを構築しています。ゲーム中のウェブチェック、それの論理を助ける
ゲームは、ウェブ上の特定の情報を見つけるためのポイントを取得することです。
ユーザーがトークン(情報の一部)を見つけたら、チェックを行い、そのチェックのポイントを取得します。ここで
は、私がこれまでに構築したデータベースです:
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 ;
そしてここでは、私のコードです。
問題は次のとおりです。ポイントが既にそのトークンに与えられているかどうかをどのように知ることができますか? 論理で私を助けてください、私は私の範囲を失ったし、私はそれを行う方法を見ることができません。おそらく間違った方向にコーディングを開始しています。 私はコード内で何をしようとしているのか説明します。ユーザーをcheckings checkingsテーブルストアは
どうもありがとうございました
<?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." ";}
?>
ありがとうございました! – lleoun