I'm looking for a way to save data based off a set of rows in another table, but I don't know how to set up the field. Think something similar to using the results of a mysql group_concat
as the field. The data is based off the unique combination of rows, rather than one row or field.
What I need to be able to do is:
- Store the array itself in the database
- Store associated data about the array
- Retreive the array
- The ability to lookup data about the array using the data in the array
Some options I've thought about:
- Saving as an ordered set concatenated into a string.
- Saving the serialized array (serialized using php's serialize function).
- Saving the set as a hashed string using a reversible hash.
None of these options seem correct so I came here hoping someone has a better answer.
Background:
Supposed I have the following tables:
users {id, other unimportant fields}
products {id, other unimportant fields}
shipments {id, user_id, product_id, date, other unimportant fields}
I want to create a new table called assigned_products
where the assigned product is based off of the unique combination of products they've received in the past. So assigned_products
should look like:
assigned_products {set_of_products_received (array), product_id (data about the array)}
I don't know of a good way to store set_of_products_received
in a database.
Example use:
Suppose I have 100 users who got product A, 100 users who got product B, and 100 users who got products A and B. Suppose then I wanted to give product B to everyone who got product A, product A to everyone who got product B, and product C to everyone who got product A and B. The assigned products table should look like:
+--------------------------+------------+
| set_of_products_received | product_id |
+--------------------------+------------+
| A | B |
| B | A |
| A, B | C |
+--------------------------+------------+
I'm just looking for a better way of storing set_of_products_received
Reading this over I realize it's a bit hard to understand, but I don't really know the appropriate terms to describe this issue (probably why I'm having trouble finding solutions). I'll be happy to clarify if anyone has any questions.