Let's say I have a database-driven site where I want to ask
for a set of information about a user, then re-present that
information later. Part of the infomation comes from "multiple"
select lists. For example the structure could look like:
NAME|AGE|HOBBIES
where hobbies could be any number of choices from this list:
Perl Programming
Reloading PerlMonks
Retipping Shoelaces
So, what is the best way to index all of the choices from the
list and insert it into the HOBBIES field in the database?
Let's say I'm using a SQL database in this case.
What I would likely do is create a second table to contain
the list data; for example:
ID|DATA
1|Perl Programming
2|Reloading PerlMonks
3|Retipping Shoelaces
Then in the user table, I use join on the list to have a
string to put into the user table like this:
Anonymous Monk|89|1:2:3
Then in my perl code I use split to break up the HOBBIES
field and then perhaps show its output by name using an array
that I loaded from the database ahead of time,
$hobbies[1], $hobbies[2], $hobbies[3]
But that just seems so obvious and inelegant, it makes me wonder
how the professional Monk might handle this situation. So, how do
you like to handle this?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.