I have a table 'users' with usual fields plus 'owned_items' and 'rating' fields and a table 'items' with their id's, and some other properties. User can posses many different items of each type and its rating is calculated by summing up the all these amounts:
rating = N1 + N2 + N3 + ...
I store the items the user owns as a string of the type:
3 4 56 22 6 67 ...
in the field 'owned_items'.
Then if I need a rating (very often), each time I turn the string in an array of numbers, calculate their sum and write the value in 'rating' field. The same is with changing the number of items of each type for a given user.
Is there a better way? May be using the relations between 'users' and 'items' tables?
Thank you.