title: Badge system and storing conditions as variables?
body: <p>I'm trying to write a piece of code that checks a users stats, be that their points, rank or num_friends and in turn awards them a badge similar to that used in SO.  The system is set so when a task (vote up, comment, etc.) is completed by a user, their user_id is recorded and queued to be evaluated at 5 min intervals by a cron job.  Is this the most efficient way of doing this?  I saw the other post about badges but am not sure if this is the method that was selected as the preferred way.</p>
  
  <p>Another question I have is about actually checking these variables (points, rank, num_friends) against the user.  I have a number of badges and want to allow admins to add their own where they select a variable, the operator (==, >=, etc.) and the value it's set to.  How do I evaluate that in an IF conditional statement?  I tried using SWITCH for the operators but can't get the variables to be evaluated correctly, like:</p>
  
  <pre><code>function checkbadges($userid,$points,$rank,$friends){
      global $database;
  
      $q = $database-&gt;db_query("SELECT * FROM badges");
      while($bq = $database-&gt;db_fetch_assoc($q)) {
          switch($bq[badge_sign]) {
            case "1":
                if($bq[badge_var] == $bq[badge_value])
                    givebadge($userid, $bq[badge_id]);
              break;
            case "2":
                if($bq[badge_var] &gt;= $bq[badge_value]))
                    givebadge($userid, $bq[badge_id]);
              break;
            case "3":
                if($bq[badge_var] &lt;= $bq[badge_value]))
                    givebadge($userid, $bq[badge_id]);
              break;
            case "4":
                if($bq[badge_var] != $bq[badge_value]))
                    givebadge($userid, $bq[badge_id]);
              break;
          }
      }
  }
  </code></pre>
  
  <p>I think I have to use eval() but I'm not sure how, any help would be appreciated!</p>