|
Posted by Tyrone Slothrop on 09/29/05 17:07
On Thu, 29 Sep 2005 08:59:33 +0200, "Bob Bedford"
<bedford1@notforspammershotmail.com> wrote:
>I've to store in some records some details. Those details aren't always
>used, and sometimes more than one are used.
>
>The user has for now 4 choices, and I must save in the database wich ones he
>selected. Soon I will have more choices.
>
>What kind of column type should I use ? I won't create 4 fields for storing
>a true or false value.
>
>I guess I should use enum or set, but wich one to use ? Are they easy to use
>and fast ?
>
>Bob
Enum limits you to store a single value from a number of possible
values, like yes, no, or maybe. A set allows you to store multiple
values separated by commas.
If strictly boolean (Y/N or 1/0), I would go with four fields. This
will simplify your queries. If the four fields have unique values
(apples, oranges,guavas,papayas), then set may be better. Why? The
FIND_IN_SET function allows you to look for a specific value in a set
field type directly in a query.
SELECT * FROM table WHERE FIND_IN_SET('apples',your_set_field);
If all you have are 1's and 0's (like 1,0,1,1) then every time you
want to query the field you will have to treat it as an array and have
to query each and every record to do it!
$qy = "SELECT * FROM table";
$rs = mysql_query($qy);
while ($row=mysql_fetch_array($rs)) {
$set = explode(',', $row['your_set_field']);
//Then evaluate the array member for a match:
if ($set[1] == 'whatever') { //do something; }
}
See the difference?
Navigation:
[Reply to this message]
|