PDA

View Full Version : how would you structure this?


DoubleV
06-27-2003, 06:37 PM
ok,
this is my first time ever doing anything real with databases.

the navigation for the site is divided into 5 main categories which have sub-links in them. Clicking on the main category will display the sub-links. the idea is to display the current category and sub-category in a different color. I could potentially acomplish this with javascript, buti think that in this situation, having it come from a db will be a better approach.

so my idea was that each link will carry some parameters with it and then i will perform a check and say something like

if ((category == passed category) && (sub-link = passed sub-link)) {
display in red
}
else {
display in blue
}


so how do you think i should be organizing this?
1. each main category is its own table, with sub-links as rows
2. everything is in 1 table and each row will have the sub-link and the main category it belongs to (but then i'd still have to have a separate table to hold all of the main categorie, right?)
3. some other better solution.

could you please tell me what the advantages/drawbacks of each solution are? this is the first time i'm trying to "design" a db, so i have no clue.
thanks!

raf
06-27-2003, 08:20 PM
Hmm. I don't completely get it.
You've got these 5 categorys. Each has subcategorys.

Ok. Now, i would do it all in one tabel, because the number of rows will be very limited (even less then 100 i assume) so a nice hiėrarchical table should do. (Don't listen, to the people that will call you oldfashion --> 1 hiėrarchical table will be way faster then a relational db)

Here's the design

ID | Label | URL | level | Parent

ID = primary key
Label = the text to display
URL = page to open --> absolute adress (http://bla.com/chapter1.php) or relative (chapter1.php)
Level = main category = 1, subcategory = 2, sub-sibcategory = 2 etc
Parent = The ID for one level up --> the category a subcategory belongs to

so your table will look something like

1 | Books | books.asp | 1 | 0
2 | CD's | cd.php | 1 | 0
3 | Records | records.php | 1 | 0
4 | Comicbooks |books_comic.php | 2 | 1
5 | Fiction |books_fiction.php | 2 |1
6 | Opera | cd_opera.php | 2 | 2
...

Now, i don't get the javascrip <--> db dilemma.
You could select this table, and then use PHP or so to build the javascript for your menu.

With this design, it's easy to determine which records should be in the menu on load ('parent = 0' or 'level = 1') + you can use the ID of the maincategorys, to display the records for there subcategories (if they select Books, you need all records where parent = 1)
You actally don't need the level-variabel, but it makes the whole design more flexible (just in case you'd later on need to include sub-subcategories)

DoubleV
06-27-2003, 10:33 PM
raf,

the amount of navigational items is not overwhelming. i counted it to be a total of 32 (top and sub level) and i do not expect it to change much in the near future.

i understand what you've said - i should stick to one tasble because it will be so small.

about javascript (ummm, i'll try to be as descriptive as i can):
let me give you a link to one of the pages i currently have: http://nimlok.com/new_site/final/custom_modular/ (not all links there work yet)
in this example, current top nav is "trade show displays" and current sub-nav is "custom modular". if i was to cklick on "modular", modular would become the current sub-nav and i need it to be in red.
but the thing is that not only do i just need to write this current thing into the page, i need to have the subs for other top categories as well (they'll be displayed when the person clicks on the top category). since i am using javascript to perform the action of displaying the stuff, i need to somehow get all those strings to be displayed accessible by javascript. i could just write it all into the <head> portion of each page using php, but i would ideally like to keep it separate. how would i get that accomplished?

raf
06-28-2003, 08:55 AM
i like your site. Nice colours (though combining that yellow/orange and the red isn't perfect) an tabelless.

I think you should keep it in one table, not only because it's a limitted number of records, but because this is typically a hierarchical setup.

I'm not sure what you're trying to acomplish with that navigation system. I'm not a javascriptexpert so i'd probably use a java-applet or so.
But for javascript, i think you can just select the complete table, store it in an array, display all items with level = 1 or parent = 0 and then have a little function that builds the sub-menu, where the items are selected based on the value they have for 'parent'.

DoubleV
06-30-2003, 03:33 PM
raf,

I'll ask about php in the php forum, so don't worry about that. thanks so much for your helpful replies! :thumbsup: