XF 2.2 Best practice for values in post?

Robert9

Well-known member
I want to save some integer values for posts. Here are some ideas on how to do it:

1. one, five or ten new fields for xf_post
to have a sum from post_values for threads, i can do: select sum of fields one, two, three for thread x.

Huh! With one field I am happy, but not with ten new fields.


2. I add a new table with a table_id; in this table, i save my values, in post, i save the table_id
Here it is easy to make sums, but to show anything, I need one query per post; not acceptable for me.
I could save the values twice, in the table and in one field of post (do i want to save values twice? We do it with custom_fields all the time!)


3. I add one field to post and save an array of values
I have all data without additional query when showing posts, but to sum my values, I can't use MySQL, i have to select all posts of a thread and sum the selected values of every post.


My add-on works now for many years and I have used version 3;

but is there any way to tell MySQL something like this:

post_1_field: 1,2,3,4,5
post_2_field: 22,1,2,3,4
post_3_field:12,3,3,3,3

Hey mysql! Take all fields from all posts with x and sum the values!


here it is possible:

post_1_field: 1
post_2_field: 2
post_3_field:1

with MYSQL:SUM()


maybe the clever people from MYSQL have added something to SUM arrays?
 
Top Bottom