<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1029642" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1029642</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/php-scoring-system#comment-1173627</link>
    <description> &lt;p&gt;I&#039;m going to assume you&#039;re using a MySQL database, PHP5, the MySQLi extension and OO notation. I&#039;d add Points (SMALLINT unsigned) and Rank (TINYINT unsigned) fields to your accounts table. A rank of 0 could mean no access to anything, 1 would mean access to some things, 2 more things, etc.&lt;/p&gt;
&lt;p&gt;Write a function to update the points of an account. It would need to take a username (or ID, whichever you&#039;re using) and the number of points to increment as parameters. So, something like&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;AddPoints&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$increment&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; global &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$databaseLink&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #FF8000&quot;&gt;// Increment Points. \&quot;accounts\&quot; is name of db table w/ account info, \&quot;points\&quot; is name of field w/ point info&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$result &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$databaseLink&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;(\&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;SELECT points FROM accounts WHERE username=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;\&quot;);&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;fetch_array&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;(MYSQLI_ASSOC);&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&#039;points&#039;];&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;close&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;();&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; += &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$increment&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&lt;br /&gt;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$databaseLink&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;(\&quot;UPDATE accounts SET points=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; WHERE username=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;\&quot;);&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;nbsp; // Update Rank&lt;br /&gt;&amp;nbsp; switch (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; case (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; &amp;gt;= 0 &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; &amp;lt; 100):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$databaseLink&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;(\&quot;UPDATE accounts SET rank=1 WHERE username=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;\&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;&amp;nbsp; case (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; &amp;gt;= 100 &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; &amp;lt; 200):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$databaseLink&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;(\&quot;UPDATE accounts SET rank=2 WHERE username=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;\&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;&amp;nbsp; case (&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$currentPoints&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; &amp;gt;= 200):&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$databaseLink&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;(\&quot;UPDATE accounts SET rank=3 WHERE username=&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$username&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;\&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;On the page that contains each feature, you&#039;d check their rank and display the feature or not accordingly.&lt;/p&gt;
&lt;p&gt;The points for logging in twice a day can be handled several ways depending on what you want? Assuming you only care about twice a day, I&#039;d have a field in my accounts table w/ the timestamp from the last time they logged in. Each time they log in, check that and if it was within 24 hours, then add points.&lt;/p&gt;
&lt;p&gt;When they complete a competition, call the addpoints fuction w/ however many points you want to add.&lt;/p&gt;
&lt;p&gt;You&#039;ll have to use a JavaScript to detect clicking on the link, or just have a script on the page that was linked to.&lt;/p&gt;
&lt;p&gt;To prevent people from taking competitions more than once, I&#039;d have a CompetitionResults table in the database listing the ID number of the competition, and the username of the person who completed it. Only add to the table when someone completes a competition. Then you can check against it before letting someone take a competition&lt;/p&gt;
 </description>
     <pubDate>Wed, 22 Jun 2005 21:40:53 +0000</pubDate>
 <dc:creator>IanD</dc:creator>
 <guid isPermaLink="false">comment 1173627 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
