Forum Moderators: coopster & phranque

Message Too Old, No Replies

function_id

to use as in normalizing

         

russgri

7:50 pm on Feb 16, 2003 (gmt 0)

10+ Year Member



I am trying to grasp the idea of using function_id as a shorthand for
normalizing.

I have a category table

<code>create table sportsmen(

subfolders? would be
hunters
subfolders of hunters:

foxhunters
birdhunters
treehunters
deerstalkers</code>

a guru made a short (get out of here) comment ...:

"You're right about the normalization, as far as I can tell. I
think you'd get by with fewer columns in your table, however, if rather than
creating one column for each category (ie, foxhunder_id, hunter_id, etc),
you instead created one column and called it "function_id" or something like
that. Then you could "F123" for a foxhunter or "H123" for a hunter. "

So what would such a structure look like ...in a table....?
or is it a class....$f123="foxhunters"; .....in a config.php?

Russell Griechen

dive into perl

9:26 pm on Feb 16, 2003 (gmt 0)

10+ Year Member



Hi russgri,

You could create a table called sportsmen which has 3 fields function_id, function_title, parent_function_id

So that records in your table would look like :-


function_id, function_title, parent_function_id
1, Sportsmen, 0
2, Hunters, 1
3, Fox Hunters, 2
4, Bird Hunters, 2

As you can see Fox Hunters will have the parent id of 2
which makes it a sub category of Hunters.

Using this table structure you can represent any depth of tree
structure as long as the parent id's point back to the higher lever
function.

This is a good way to normalise the data in a database.

russgri

5:56 pm on Feb 18, 2003 (gmt 0)

10+ Year Member



Thank you very much
That certainly is clean and elegant.
...and can be used in a lot of other Categories as well
*
*Then make the table
*
create table hunters(
hunter_id,hunter_name,address_id,Other_affiliations_id

right? I am not sure about the swap table.