Storing multiple item settings in database

59 views Asked by At

I'm building a gallery. Each image is a row with name and src and order etc.

I want to have 3 more options per image: Featured, Visible, Disabled.

Should I have those as columns?

Or have just 1 column settings and store a 3 binary numbers?

For example:

111 = Featured, Visible, Disabled

110 = Featured, Visible

010 = Visible

001 = Disabled

Or I can even convert that to DEC and simply store a 0 to 7 (like CHMOD style)

What is the best way to do this?

Thanks!

2

There are 2 answers

0
Drew On BEST ANSWER

depends. are only programmers with pocket-protectors looking at data and app code? i am all for complexity but i would say spring for a little overhead. also, despite valiant efforts, i have failed to do bit-wise searching in mysql

Problems with bit-wise searching, see this.

0
Rick James On

If you are asking how to store/manipulate in MySQL...

  • SET ('Featured', 'Visible', 'Disabled')
  • TINYINT UNSIGNED and do bit arithmetic; see 1 << 2 give you 4; 0x4 is a way to express literal 4 in hex; a | b is bitwise OR, etc.