The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

You should decide which <a> to highlight based on which page you're on on the server side. So if you want to highlight the anchor for the current page, with PHP you add a class "active", for instance, to that anchor. Likewise, you should add the class for the parent ul based on this too. If you can do it on the server side, do it on the server side. If you need it to respond to the user's actions, use javascript.

However, if you really need to use javascript, first we need to know which anchor is the one for the current page. What's this javascript you're using for this?

In that case you need to build an array of the links first (from the database) and check which one is active. Based on that, you set the class of the parent UL and then you make the list of links with the array you made before.

Andrew, I don't think you understand how arrays work. Since you're using mysql_fetch_assoc(), I think the way you're doing it $row_rsSANavBars will be an array of the elements of the first row only. You should use it in a while loop (also you have very complicated variable names):

Read the manual on mysql_fetch_assoc - it returns an associative array only for the current row. This is why $row['Name'] is the same each time, because in the loop we haven't been doing anything with it. So $row['Name'] will be the Name in the last row from the query.

But now I see you're putting "WHERE Type = 'SA'" in the query, so there is no point in determining what the type is if you already know what it is!! TO be honest your code doesn't make much sense to me. This might be what you need:

Raffels - sorry for the confusion I have caused!
Type is just a letter code in my db that tells me which main nav tab the link belongs to (e.g. Type SA = Secure Access main nav, so any links with Type SA should show up under the Secure Access tab)

I am making progress but still not coming up with the right solution. I have a horizontal nav bar that has drop down navigation - the drop down navigation is populated from my database based on the user the list will be different. Meaning I have 1 table that stores the navigation links (called sanavbars) and another that stores the users (called sauser) and then a 3rd table that stores which links from sanavbars each user has access to.

Now I want to change the class of the horizontal nav bar which contains the current page (e.g. basename($_SERVER['SCRIPT_NAME'])) in one of its sub navigation links.

for each of the five tabs. The problem with this code is that it only returns one link for the sub nav? I assume that this is because as you point out that fetch_assoc returns only associating row. Should I use fetch_row?

You are repeating DB queries there. Bad. You only need to do the query once - that's what's got you into this mess in the first place!

You seem to be randomly copying and pasting things in there without actually giving much thought to what is going on or trying to understand the code.

Another problem is that you mention "navbars" (plural) but from your description it seems to me there is only one navbar with five items in it, and each one when hovered shows a submenu. Also, you want the submenu containing the link to the current page to have a different class name. Is this right? So the basic structure is like this:

In that case, that's not the proper markup, because the outer list is no longer a list - it only contains one item! You'd be better off using a div, or a list like I posted. I hope you realise that LI and UL and DIV items are quite similar from a styling point of view. You can just treat them as boxes and apply padding, margin and borders like you would with a DIV.

My version and yours area actually very similar. So instead of giving the top level ULs different classes, you should give the top-level LI items different classes.