1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Table structure for a directory's list of categories

Discussion in 'Databases' started by relixx, Dec 17, 2006.

  1. #1
    I've started coding a directory site as a side-project and am busy with the database design, and I've come up to a part I'm not so sure how to do.

    I'm trying to come up with an efficient way to do a scalable category system, and currently I have a single table that lists the categories, with each entry consisting of a 'parent_category' (the category above the current one) and 'child_category' (the categories below the current one) field. What will happen is that if you view a category page it'll search the categories table and return a resultset consisting of all the rows where parent_category or child_category matches the current category id.

    Does anyone know of a better way to do this?
     
    relixx, Dec 17, 2006 IP
  2. smallbuzz

    smallbuzz Peon

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use the parent_category column to determine all the childs, so your child_category column is redundant and is not needed.
     
    smallbuzz, Dec 19, 2006 IP
  3. naphets66

    naphets66 Well-Known Member

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #3
    I don't know if it is right or not, but I have only had three columns in every category table I've used:
    category_id,category,parent_category

    Of course, you can add extras such as category description, but as far as usability goes this works for me.
     
    naphets66, Dec 20, 2006 IP
  4. relixx

    relixx Active Member

    Messages:
    946
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    70
    #4
    haha, yeah, i realised that about 5 seconds into coding the thing :p

    This is probably the simplest way to do it so I'll stick to it. Only thing that annoys me is doing the navigation bread crumb for the category (eg parent cat -> sub cat -> sub cat etc). I pretty much have to start at the bottom cat and search the table each level up to try and see if that was the last one.
     
    relixx, Dec 20, 2006 IP