Nicholas Vettese wrote:
If I have a multiple choice on a form and want to store that in my DB, then how should I set up my table? I have been reading up on these, but everyone seems to have a different opinion on how to accomplish this task. What I am looking to do give the user a few options to check when submitting a form.

<select name="sports" multiple id="sport_type">
<option value="baseball">Baseball</option>
<option value="football">Football</option>
<option value="soccer">Soccer</option>
<option value="hockey">Hockey</option>
</select>

Would my table look like this:

....
CREATE TABLE sports (
sports_id int(11) not null auto_incremement,
sport_name text not null,
primary key (sports_id)
);

INSERT INTO `tbl_options` VALUES (1, 'Baseball');
INSERT INTO `tbl_options` VALUES (2, 'Football');
INSERT INTO `tbl_options` VALUES (3, 'Soccer');
INSERT INTO `tbl_options` VALUES (4, 'Hockey');
...

Would using "text" as the way to store make it easier to retrieve the data in a 
manner that would be readable on a web page?

Thanks,
Nick

I personally would fill the values with the ID numbers myself for a couple of reasons:
a) Your sports_id is PK and is auto incremented
b) You'll save some bytes for your users for downloading (and save some for yourself) by using a number (just a few bytes per id, opposed to the entire sports name.)

Text would make it easier later if you ever needed to put some realllly long sports name, but a char field may work in this case as well.

...
You would end up with this where the sports_id is used for the value.
<select name="sports" multiple id="sport_type">
<option value="1">Baseball</option>
<option value="2">Football</option>
<option value="3">Soccer</option>
<option value="4">Hockey</option>
</select>


Tho, this is what *I* would do. It may not be the best solution. You'll have to look at a number of factors before deciding on how to store/display data to/from a database. You'll want something fast and decently scalable, with out seeing the whole picture it is hard to tell you exactly what *you* should be doing. :-D


--
Thanks,
James

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to