0

I know and understand why you shouldn't do that. I am sorry but there is no other way in this situation. However the database is not meant to stay there forever anyway (the content gets deleted after every hour).

What is the best way I could store multiple values in one field? How can I retrieve those values?

The values are like this:

SomeID -> Time, SomeID -> Time.... so I guess an array would be a solution?

5
  • do you need to search for the values? like, do you have to query for them? Commented May 15, 2014 at 11:40
  • I do not need to query for them Commented May 15, 2014 at 11:41
  • 1
    There's three ways out of a number of possibilities that you can store your data: PHP serialize, json, and xml. You can search in MySQL with xml, but not in the other two. Commented May 15, 2014 at 11:42
  • Just store a comma-delimited string (or a json string - great idea - as suggested above). Commented May 15, 2014 at 11:42
  • Till you dont need to search on this field, you can store the data in whatever format you like. However, as suggested above prefer JSON or serialized array though. Commented May 15, 2014 at 11:52

1 Answer 1

3

If you do not need to search for values within that field, I suggest you go about using PHP serialize/unserialize or json_encode/decode.

This will allow you to place an array structure into a mysql field, and then later grab that data and deserialize/decode it. There is much debate as to which is better. Both have their pros and cons. I personally prefer json because I can use it in jQuery should the opportunity arise, and it is easier to read.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.