0

I'm not totally newbie but also not the master of php&mysql, now I'm using Codeigniter for my website.

I arranged some user xp points for some events for website when you add question to website you are earning 10 points, if you wrote answer you are getting 20 points. etc..

So my user_xp table has these columns:


user_id    xp_points    level

So I'm just curious to make 40 different levels for my users between different points, so I don't want to calculate them again again 40 time by if cases, so if anyone has idea it will help me alot. (If every level was same point it will be easy but higher levels should be more difficult is'nt it?)

Thanks for your help.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Mehmet Uyarovic
  • 304
  • 2
  • 9

2 Answers2

1

You could use some Geometric Progression to calculate the level based on the user's XP.

vcampitelli
  • 3,168
  • 1
  • 12
  • 13
0

if or switch case, no way out =) , byu you need encapsulate it in one place, like helper, and make something like function getUserLevel($xp_points) { .... return $level; }

san4o
  • 196
  • 1
  • 7
  • so I need one helper that will calculate my levels with my conditions so in another case we will use if or switch case but only in helper :) – Mehmet Uyarovic Mar 07 '13 at 16:06