Note that there are some explanatory texts on larger screens.

plurals
  1. POWeb checking in game, help with the logic of it
    primarykey
    data
    text
    <p>I'm building a web which has a game in it.</p> <p>The game is about getting points for finding certain information in the web.<br> When the user finds a token, a piece of information, does a checking and he/she gets points for that checking. </p> <p>Here's the database I've built so far: </p> <pre><code>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 ; </code></pre> <p>And here's my code. </p> <p>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. </p> <p>Thanks very much </p> <pre><code>&lt;?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)&amp;&amp;($row0['userid']==$userId)&amp;&amp;($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." ";} ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload