Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

how to set up database driven navigation menue How

Posted 17 Dec 2004 14:09:31
1
has voted
17 Dec 2004 14:09:31 Stephan Wirth posted:
Hi all,
I am new to this forum, I hope my three weeks odysse will end soon. I need HELP!!! Otherwise i will go crazy <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>
The other thing is I am quite new to dynamic web design, so maybe there is a simple solution to my problem.
The problem is to design a site navigation wich is driven by a database. I try to redesign a page wich exist of about 100-150 pages. And my chief is quite "unstable", which means to change the site navigation every 3 hours, ad pages, delete pages,... I think you imagine.
So I decided to generate the page navigation by database using dreamweaver.
I want to make it similar to the halo template in dreaweaver or on the macromedia webpage www.macromedia.com (It doesnt have to look exatly like it, but has to have a submenue, and this rollover effekts).
What I did 3 weeks long and failed is as follows:
1. To generate the global nav i designed a MySQL-database and created a table called "nav" with fields "home", "id". In the filed "home" I write all the menue items, "id" is primary key and autoincreament.
The first big struggle was, that I wantetd to put the data using dynamic table. But the problem was that both, the rollovers didn`t work as the should, the whole menue is making rollovers, but the more important thing, no submenues where working, only the submenue 1, which is clear, because of the CSS style sheet.
BUT HOW IS IT POSSIBLE TO GIVE DYNAMICAL DATA IN A TABLE ITS OWN STYLE AN LINK??
What I have don is to make for every menue item a single binding, wich looks like this:
mysql_select_db($database_navigation, $navigation);
$query_nav = "SELECT nav.home FROM nav WHERE nav.id = 2";
$nav = mysql_query($query_nav, $navigation) or die(mysql_error());
$row_nav = mysql_fetch_assoc($nav);
$totalRows_nav = mysql_num_rows($nav);
and give out the data wich looks like this:
&lt;div id="globalNav"&gt;
&lt;div id="globalLink" class="glink"&gt;
&lt;a href="#" id="gl3" class="glink" onmouseover="ehandler(event,menuitem3);"&gt;global
link&lt;/a&gt;&lt;a href="#" id="gl4" class="glink" onmouseover="ehandler(event,menuitem4);"&gt;&lt;?php echo $row_nav['home']; ?&gt;
&lt;/a&gt;&lt;a href="nav.php" id="gl5" class="glink" onmouseover="ehandler(event,menuitem5);"&gt;&lt;?php echo $row_ortho['home']; ?&gt;&lt;/a&gt;&lt;a href="#" id="gl6" class="glink" onmouseover="ehandler(event,menuitem6);"&gt;&lt;?php echo $row_trauma['home']; ?&gt;global
link&lt;/a&gt;&lt;a href="#" id="gl7" class="glink" onmouseover="ehandler(event,menuitem7);"&gt;global
link&lt;/a&gt;
&lt;/div&gt;
This works perfektly, but I thinks it ia lot of code, and if I need to add a menue item, there is no chance. I thougth about to write code for additional items an genrate bindings as dummys, so if a menue item is addes to the database, all is ste up.
BUT THIS CODE IS VERY COMPICATED AND I CAN NOT IMAGINE THAT DOING LIKE THIS IS LIKE SOMEBODY IS DOING WHO IS KNOWING WHAT HE DOES!!!

the sekond problem is the pretty much the same as mentioned above, regarding the submenues.
I created another tabel in the MySQl-database, calles "subnav" containing the fields "id", "subnav1". "subnav1" is containing the menue items and "id" is primary key, autoincrement.
for the reason not to generate for every submenue item a "personal"-binding, I decided to use a dynamic table again, because roll overs are not that important in submenue, but if it would be possible this would be perfect! But the same problem again: how can I assign a spezific link to the data displayed dynamically by the tabel?

The plan I have in my mind is, to ad a field in the MySQL table "subnav" called "url". Plan is to write in the link the menue item should have. BUT I FAILED TO REALIZE THIS IDEA, BECAUSE I HAVE NO IDEA HOW TO MAKE IT. But this would be the gold solution for me, beause, then everthing is made dynamically, so no preconfigured code will be neccessary!

So thanks for reading all this and to try ro understand my problems. Is something like I am dreaming of possible?
Thanks again.

Cheers stephan<font face='Arial'></font id='Arial'>

Replies

Replied 18 Dec 2004 17:08:24
18 Dec 2004 17:08:24 Simon Martin replied:
Wow Stephan... There's a lot going on in this question. It might be worthwhile breaking it down into smaller chunks.

<b>Database:</b>
From what you've said it doesn't seem like there is any relationship between your tables "nav" and "subnav", so how does your sub nav menu know which links to show when you select something from the main nav?
Normally you would link each item in a child table to the parent with a foreign key (the primary key from the main table). Therefore if in your main nav you had an item "Projects" with an ID of 4 (check the status bar when you mouseover projects on the menu in dmxzone) you would need to have that ID in each record in your subnav table that you want to associate with that item.
To build the subnav you would then create a recordset that filters based on the ID value; something like
SELECT subNavID, title FROM subnav WHERE navID = varMenu (where varMenu is the value passed to it by the hyperlink on your menu)

It looks like you might need to revise your database structure a little too.
Certainly every table needs an ID but I'm not sure that "home" (in table nav) is the best name for the headings you want to display, maybe something like section would be better. You might also consider adding a flag to each record; "isActive" a boolean datatype (yes/no or bit) that would let you 'turn on' or 'turn off' each item depending on what your chief is saying at that moment in time! (this will save you trying to delete an item that has records associated with it - a big no no as it violates referential integrety)
You could also consider changing the way you name your tables e.g. tblNav tblSubNav - this will make it easier to understand your code.

<b>Code:</b>
To tidy up your html for the navigation I would suggest using a list &lt;ul&gt; css.maxdesign.com.au/listamatic/ demonstrates lots of cool designs that could be applied using just CSS (you can look at the code there and it might give you some ideas) also they have a link to List Generators that will do the hardwork for you. And a link to an extension from DMXZone that'll make it VERY easy to generate the code in DMX itself.
To populate the list just make a recordset for the items in your main nav table and stick it in a repeat region. If you've added the flag I suggested earlier then the recordset would be something like
SELECT navID, navText FROM tblNav WHERE isActive = 'Y'
You need the ID so that you can pass it to the recordset to populate the subnav

<b>Building the page:</b>
Finally in order to build the pages themselves you would again need to build a recordset and filter that based on the subNavID value.

There is an article by Rachel Andrew Dynamic menus with ASP and CSS <u>www.dmxzone.com/showDetail.asp?TypeId=28&NewsId=6116</u> that you might find helpful. Its premium content, so $1 (US dollar) but might be worth it even though its in ASP as the principles will be the same no matter what scripting language you are working in

HTH
let me know how you get on


Live the life you love
Love the life you live

Simon

[DWMX 2004]|[SQL]|[ASP/VBScript]|[XP-Pro]
Replied 23 Dec 2004 01:32:59
23 Dec 2004 01:32:59 Stephan Wirth replied:
Hi Simon, First of all thank you verymuch for all you help. the last days i tried a lot, but I failed a lot also. the probelm I have is how to to show the submenue for let me say mainmenue topic 3 when the cursor is over this topic? similar to the macromedia hompage. is this possible without using javascript?
showing the Mainmenue is not that problem and adding the links to the menue topics I found in one of my books a good way to to it. please have a look at www.orthopaedie-samedan.ch.
Thank you very much and have a great day.

Cu Stephan

Reply to this topic