storing different types of data in 1 model

Hi all,

I'm creating a statistics system for events. When an event has passed, an admin can enter statistics for that passed event. Every user attending the event and the event itself have statistics. The problem is that depending on the type of the event, the type of statistics for both users and event can change. eg: for one event the number of remarks and time present will be registered for another event the name of the company he represents

I'm struggling on how to implement this especially database wise. I can ofcourse create a table that contains all possible statistics data and than only fill in the rows that matter for that event. the downside is that I lose a lot of storage since a lot of rows are left blanc.

maybe someone has an idea on how to solve this?

thanks in advance. Stijn

Tarscher wrote: The problem

is that depending on the type of the event, the type of statistics for both users and event can change. eg: for one event the number of remarks and time present will be registered, for another event the name of the company he represents

You could approach this with a key-key value type of table definition.

STATISTIC:   EVENT_ID   STAT   STAT_TYPE   STAT_STRING

EVENT_ID can link back to the event STAT is the name of each statistic, like REMARK_COUNT, TIME_PRESENT, or COMPANY_NAME, however many you'd like to keep (I'd probably keep the valid list in another table). STAT_TYPE is the data type of the value "stored", which directs you to which of the remaining fields holds the valid value for this record. STAT_STRING is the stringified version of the data.

You could record any number of different statistics for any event, it's row-heavy, column-light, and has some of its own issues, but it's workable.

I'm sure there's a better approach, but it's been like 10 years since I worked on an issue where I wanted to store an arbitrary collection of attributes.

Ar Chron wrote:

STAT_TYPE is the data type of the value "stored", which directs you to which of the remaining fields holds the valid value for this record.

Arrgh... no edit...

STAT_TYPE is the data type of the value stored, which tells you the transformation to apply to STAT_STRING...