Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich is more efficient in PHP, explode() from a database of nested switch case
    primarykey
    data
    text
    <p>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</p> <p>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</p> <p>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</p> <p>b|b|s|g|c|g|s|j</p> <p>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</p> <p>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</p> <p>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</p> <p>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</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload