List:General Discussion« Previous MessageNext Message »
From:Thimble Smith Date:August 31 1999 2:22am
Subject:Re: Storing an array?
View as plain text  
At 08:51, 19990831, Rod wrote:
>On a form I have several catagories in which one catagory may have up to 50
>checkboxes. Would someone kindly suggest the most efficient way to save the
>values to a table. I can store the values as an array into a variable with
>PHP but is it possible to then store this array into one field in a table?
>And if so, how do I extract the array values from the field.

Rod, you can use a SET type.  Read all about it in the manual.

Another option is to have two extra tables, like this:

CREATE TABLE categories (id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
                         name CHAR(15));
CREATE TABLE assigned_categories (thing_id INT UNSIGNED NOT NULL,
                                  category_id TINYINT UNSIGNED NOT NULL
                                  PRIMARY KEY (thing_id, category_id));

Now for each thing in your things table you can have any number of
categories selected.  This is basically the same thing as using a SET
value, except it's the normal(ized) way to do it.

Tim
Thread
Storing an array?Rod31 Aug
  • Re: Storing an array?Thimble Smith31 Aug
  • Re: Storing an array?Urb LeJeune31 Aug