Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1106543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:48:33+00:00 2026-05-17T01:48:33+00:00

I have users’ table users , where I store information like post_count and so

  • 0

I have users’ table users, where I store information like post_count and so on. I want to have ~50 badges and it is going to be even more than that in future.

So, I want to have a page where member of website could go and take the badge, not automatically give him it like in SO. And after he clicks a button called smth like “Take ‘Made 10 posts’ badge” the system checks if he has posted 10 posts and doesn’t have this badge already, and if it’s ok, give him the badge and insert into the new table the badge’s id and user_id that member couldn’t take it twice.

But I have so many badges, so do I really need to put so many if’s to check for all badges? What would be your suggestion on this? How can I make it more optimal if it’s even possible?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:48:33+00:00Added an answer on May 17, 2026 at 1:48 am

    optimal would be IMHO the the following:

    have an object for the user with functions that return user specific attributes/metrics that you initialise with the proper user id (you probably wanna make this a singleton/static for some elements…):

    <?
    class User {
     public function initUser($id) {
      /* initialise the user. maby load all metrics now, or if they 
      are intensive on demand when the functions are called.
      you can cache them in a class variable*/
    
     }
     public function getPostCount() {
      // return number of posts
     }
     public function getRegisterDate() {
      // return register date
     }
     public function getNumberOfLogins() {
      // return the number of logins the user has made over time
     }
    }
    ?>
    

    have a badge object that is initialised with an id/key and loads dependencies from your database:

    <?
    class Badge {
     protected $dependencies = array();
     public function initBadge($id) {
      $this->loadDependencies($id);
     }
     protected function loadDependencies() {
    
      // load data from mysql and store it into dependencies like so:
    
      $dependencies = array(array(
       'value' => 300,
       'type' => 'PostCount',
       'compare => 'greater',
      ),...);
      $this->dependencies =  $dependencies;
    
     }
     public function getDependencies() {
      return $this->dependencies;
     }
    }
    ?>
    

    then you could have a class that controls the awarding of batches (you can also do it inside user…)
    and checks dependencies and prints failed dependencies etc…

      <?
            class BadgeAwarder {
             protected $badge = null;
             protected $user = null;
    
             public function awardBadge($userid,$badge) {
              if(is_null($this->badge))  {
               $this->badge = new Badge; // or something else for strange freaky badges, passed by $badge
    }
               $this->badge->initBadge($badge);
    
              if(is_null($this->user))  {
               $this->user = new User;
               $this->user->initUser($userid);
              }
              $allowed = $this->checkDependencies();
              if($allowed === true) {
               // grant badge, print congratulations
              } else if(is_array($failed)) {
               // sorry, you failed tu full fill thef ollowing dependencies: print_r($failed);
              } else {
               echo "error?";
              }
             }
             protected function checkDependencies() {
              $failed = array();
              foreach($this->badge->getDependencies() as $depdency) {
               $value = call_user_func(array($this->badge, 'get'.$depdency['type']));
               if(!$this->compare($value,$depdency['value'],$dependency['compare'])) { 
    
                $failed[] = $dependency;
               }
              }
              if(count($failed) > 0) {
               return $failed;
              } else {
               return true;
              }
             }
        protected function compare($val1,$val2,$operator) {
         if($operator == 'greater') {
          return ($val1 > $val2);
        }
        }
            }
            ?>
    

    you can extend to this class if you have very custom batches that require weird calculations.

    hope i brought you on the right track.
    untested andp robably full of syntax errors.
    welcome to the world of object oriented programming. still wanna do this?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have users table and want to SELECT some rows by bitmask criteria. I'll
i have users table and i have posts table i want select from users
I have users(user,pass,email) table and I want to get the count of user where
I have a subdirectory of users that I want to limit each subfolder to
Scenario: I have users that want to be able to change their username (unfortunately
I have users and projects resources and join table that connects them called project_members.
I have users list table how i can navigate on url: ../users/showprofile?userid= I want
I have users that are putting in links to youtube videos and we want
i have USERS TABLE that contains the following fields _id name number_of_posts and i
I have users selecting a DateTime using a caldendar/clock popup that allows them to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.