title: Current database-structure improvements & implementing badge system
body: <p>I'm making a website that has logos that need to be guessed. Currently this is my db setup:</p>
  
  <pre><code>Users(user_id, etc)
  Logos(logo_id, img, company, level)
  Guess(guess_id, user_id, logo_id, guess, guess_count, guessed, time)
  </code></pre>
  
  <p>When a user does a guess, it's done with an ajax request. In this request, 2 queries are done. 1 to retrieve the company-data (from <code>Logos</code>), one to insert/update the new guess in the db (<code>Guess</code>).</p>
  
  <p>Now, on every page-load I need to know the total amount of guesses, and how many logos there are per level. This requires 2 queries - one that checks the <code>Logos</code>, one that gets the amount of guessed (<code>guessed = 1</code>) guesses from <code>Guess</code> per level.</p>
  
  <p>Now I want to implement some kind of badge-system, like here on SO. Reading through some <a href="https://stackoverflow.com/questions/522943/best-way-to-store-badge-criteria">other questions</a>, I saw that it might be better to have a separate table containing a the total amount of guesses and such, so that it takes the same resources if a user has 10 guesses or 10000. I didn't do this for several reasons:</p>
  
  <ul>
  <li>requires an extra query in my ajax-call, which I'd like to keep as short as possible</li>
  <li>page-reloading shouldn't happen that frequently, so that shouldn't take too long</li>
  <li>I wouldn't know how to count the total amounts of guesses per level, unless the table would look like: <code>AmountOfGuesses(id, user_id, level, counter)</code> but then it'd take more resources depending on the amount of levels you've unlocked.</li>
  </ul>
  
  <p>As for the badge system, I know the terms should just be checked eg when a user submits an answer. If course this requires yet another query every time an answer is submitted, namely to check the total amount of answers the user has. Then depending on that amount, the badge should be assigned. As for the badges, I was thinking about a table-structure like so:</p>
  
  <pre><code>Badges( badge_id, name, description, etc)
  BadgeAssigned( user_id, badge_id, time )
  </code></pre>
  
  <p>Does this structure seem good for badges?</p>
  
  <p>Is the current structure of the rest of my database good, or is it better if it is adjusted?</p>