How to compress a html color code properly?

Hi I am storing html color codes as strings in my sql database.

e.g. a html color usually have 7 characters, e.g. "#f5f6f0", and a database field called "colors" consists of dozens of these colors in one string, such as "#f5f6f0 #e3e5e6 #3c2d5e ..."

Right now I felt it took too much space and wanted to compress it using a simple and easy to understand method, any suggestions?


2 answers

  • answered 2018-02-13 01:53 Ctznkane525

    A database column should never contain multiple values. You need a 2nd table:

    Let's say your table was called records, and the id called record_id. If you need multiple colors, you should have a second table called record_colors, with a combined PK on that table of ( record_id FK from the 1st table, color ).

  • answered 2018-02-13 04:56 Joseph Armstrong

    Try using shorthand hex colors when possible.

    .dark-yellow {color:#ffcc00;} .dark-yellow {color:#fc0;}

    CSS Hex to Shorthand Hex conversion