Re: Please Help - getting a hightlight depending on selected page

From: Date: Wed, 22 Aug 2001 21:53:11 +0000
Subject: Re: Please Help - getting a hightlight depending on selected page
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-63969@lists.php.net to get a copy of this message
Okay, well you could either put code like this into each td cell like this: <td class="navtext" <?php if (sect == 5) print "id=\"sel\""; ?>> That is kind of ugly, however. A more elegant solution would be to make an array containing the links then do a loop kind of like this (I'm just typing the code off the top of my head, so there is likely to be some errors): $menuItems = array('Home', 'Introduction', 'Changes &amp; Cuts', 'Scores', 'Orchestra', 'Synthesizers', 'Sound System', 'Articles'); $i = 0; foreach ($menuItems as $item) { if($sect == $i) { print "<tr><td class=\"navtext\" id=\"sel\"><a href=\"\">$item</a></td></tr>\n"; } else { print "<tr><td class=\"navtext\"><a href=\"\">$item</a></td></tr>\n"; } $i++; } The obvious problem with my solution is the links will also presumably have to be entered into an array, and I don't think the foreach construct can work on two arrays simultaneously, but you can use the $i variable as the index to your second array. In article <20010822210642.1116.qmail@pb1.pair.com>, martin@mixermanic.co.uk (Martin Hughes) wrote: > OK here's the code in the page: > > <!-- Start Navigation --> > <div id="navbar"> > <table class="navtable" width="160" cellpadding="4"> > <!-- Navigation Bar Heading --> > <tr> > <td class="navhead">Welcome</td> > </tr> > <tr><td class="navtext" id="sel"><a > href="">Home</a></td></tr> > <tr><td class="navtext"><a > href="">Introduction</a></td></tr> > <tr><td class="navtext"><a href="">Changes &amp; > Cuts</a></td></tr> > <tr><td class="navtext"><a > href="">Scores</a></td></tr> > <tr><td class="navtext"><a > href="">Orchestra</a></td></tr> > <tr><td class="navtext"><a > href="">Synthesizers</a></td></tr> > <tr><td class="navtext"><a href="">Sound > System</a></td></tr> > <tr><td class="navtext"><a > href="">Articles</a></td></tr> > <tr><td class="navtext"><a href="">21st Century Les > Mis&eacute;rables</a></td></tr> > <tr><td class="navtext"><a > href="">Information</a></td></tr> > <tr><td class="navtext"><a href="">Discussion > Forums</a></td></tr> > > </table> > </div> > <!-- End Navigation --> > > > I am using this 1 page as the php 'template' with content added depending on > the url. For example, to go to the synthesizers page the url is: > index.php?sect=5&id=0&page=31 > > where sect=5 is the part that sets the menu highlight (the menu is alway the > same, hard-coded into the page - all I want to do is change the css id="sel" > from Home to Synthesizers. > > Cheers > > Martin > > -- __________________________________ Gabe da Silveira, Web Designer Twin Cities Student Unions University of Minnesota http://www.coffman.umn.edu wFone: (612)624-7270 eMail: jiblet@visi.com hPage: http://www.visi.com/~jiblet

« previous php.general (#63969) next »