Help with collapsing menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ajfresh
Forum Newbie
Posts: 3
Joined: Wed Nov 24, 2010 11:19 am

Help with collapsing menu

Post by ajfresh »

Hi there, I'm a newbie, and I would really like some help regarding this issue I have with my menu.

First the code:

01 function public_navigation($sel_subject, $sel_page, $public = true) {
02 $output = '<ul id="sidebar_tags_ul">';
03 $subject_set = get_all_subjects($public);
04 while ($subject = mysql_fetch_array($subject_set)) {
05 $output .= "<li><a href=\"index.php?subj=" . urlencode($subject["id"]) . "\"";
06 if ($subject["id"] == $sel_subject['id']) { $output .= " class=\"selected_white\" . "; }
07 else { $output .= " class=\"sidebar_links_white\" . "; }
08 $output .= ">{$subject["menu_name"]}</a></li>";
09 if ($subject["id"] == $sel_subject['id'] || $subject["id"] == $sel_page['subject_id']) {
10 $page_set = get_pages_for_subject($subject["id"]);
11 $output .= "<div class=\"sidebar_links\">";
12 while ($page = mysql_fetch_array($page_set)) {
13 $output .= "<a href=\"index.php?page=" . urlencode($page["id"]) . "\"";
14 if ($page["id"] == $sel_page['id']) { $output .= " class=\"selected_orange\" . "; }
15 else { $output .= " class=\"sidebar_links\" . "; }
16 $output .= ">{$page["menu_name"]}</a><br />";
17 }
18 $output .= "</div>";
19 }
20 }
21 $output .= "</ul>";
22 return $output;
23 }

Let me explain:
If I select a subject and if this subject has pages under it, the menu will expand and it will show all available pages in the selected subject. Fine!
However...if I then proceed to click on a page within the subject, the page does select but the menu collapses, and thus will not show all available pages in the subject anymore.
This means, in order to visit another page within the selected subject, I will first have to return to the selected subject (to open the menu) to be able to select another page inside the subject.

Now:
I did fool around a bit but could not get a satisfactory result. I added to line 09 in the if statement : || $subject["id"] == $sel_page['subject_id'].
Now the menu does not collapse on selecting a page, but if for example the $subject['id'] == 2 & $sel_page['subject_id'] ==2, (wich is true in this case) then both will be selected if I select either of them.

What do I need to do to solve this problem?

Image
ajfresh
Forum Newbie
Posts: 3
Joined: Wed Nov 24, 2010 11:19 am

Re: Help with collapsing menu

Post by ajfresh »

sorry the screenshot did not display as wanted.

http://xtence.com.pt/images/screenshot.jpg

Here is a link to the screenshot
ajfresh
Forum Newbie
Posts: 3
Joined: Wed Nov 24, 2010 11:19 am

Re: Help with collapsing menu

Post by ajfresh »

I figured it out!

Code: Select all

09. [color=#FF0000]if ($subject["id"] == $sel_subject['id'] || $subject["id"] == $sel_page['subject_id']) [/color]
Post Reply