|
Posted by Bob Bedford on 09/30/05 10:01
> 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?
Yes thanks for your explanation Tyrone, it's all clear now.
Cheers.
Navigation:
[Reply to this message]
|