Я создаю сеть, в которой есть игра.
Игра о получении очков за поиск определенной информации в сети.
Когда пользователь находит токен, часть информации выполняет проверку, и он / она получает баллы за эту проверку.
Вот база данных, которую я создал до сих пор:
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." ";}
?>