i’m programming a system which records users achievements in games by collecting Trophy data which is uploaded to the system, it got it to work fine but i have started to think about one part of the system i can do in 2 different ways
this part of the system gathers a Trophy’s rank (Bronze, Silver, Gold, Crystal, Jade) and how many points it’s worth, each user as a record in a game’s table, each field apart from the tables primary key and the user_id foreign key represent each trophy that can be obtained in the exact order they are listed, this means they aren’t sorted in any way which a machine can easily search though
how i have combat this is that there is another table which each record contains the game and a string which lists the rank order of the trophies separated by |’s so when i use explode(STRING,”|”) i get an array and each index of the array is a single character, it can look something like this
b|b|s|g|c|g|s|j
that is just the trophy rank, the point value is done though function where i pass the game id and trophy id and a switch case statement will first check what game i have passed while nested switch cases in each case will check the id, in each case of these they return the point value of a trophy
naturally i didn’t plan out my code, the rank string above originally didn’t have the | and i didn’t do the point values like that cause unlike the rank, a score value van very between 1 and 3 digits, now i know i can do the same with the point value as i did with the rank order
i want to know which method is more efficient for the web server and for browsers, pulling a string from a database and using explode(STRING,”|”) (and intval() to convert the point values from strings to integers, need them like that for calculations) or calling a function with switch case statement like a look up table or if what i already have is efficient enough
i’m not really interested in trying to do what i am doing in a completely different way just to make it even more efficient as these methods perfectly fit the nested loops in which i am using them in
try reconstruct your db, there could be a table achievements with a many2many relations to users,trophy tables..columns user id, a trophy id, total points and/or other data with a view you can get the username,trophy type, and points