PDA

View Full Version : menu CSS select "current" using JSP or PHP


student101
07-06-2008, 07:30 AM
I am currently using CSS with PHP to keep the menu state "current" (CSS value)

It works with PHP like this:
<li><a href="faq.php" <?php if ($page == 'faq.php') { ?>class="current"<?php } ?>>FAQ</a></li>
I have decided to update it using only a database, like this:
<?php do { ?>
<li><a href="?page=<?php echo $row_rsnav['id']; ?>" <?php if ($page == 'what to put here') { ?>class="current"<?php } ?>><?php echo strtoupper($row_rsnav['pagename']); ?></a></li>
<?php } while ($row_rsnav = mysql_fetch_assoc($rsnav)); ?>
Is this possible with?

Cheers

davidj
07-06-2008, 07:35 AM
dont know what your meaning

student101
07-06-2008, 07:48 AM
What I mean is, I want the selected menu item to stay selected

At the top of the page I use this:

<?php $page = basename($_SERVER['SCRIPT_NAME']); ?>

It grabs the page name and uses it in the PHP query to set the current state of the menu.
The problem is that I am using one page, ie: "index.php" the page data would be based on "id" or "page"


I tried this way: (highlights all menu items?)
$pageid = $_GET['page'];
Using this:
<?php if ($pageid == "5") { ?>class="current"<?php } ?>
It highlights all the menu items and not the one, which is normal as it's not working as planned.

student101
07-06-2008, 09:06 AM
Solved: http://www.askthecssguy.com/2008/04/prasun_asks_the_css_guy_how_to_1.html

Thanks

Cheers

davidj
07-06-2008, 11:00 AM
if(!(strcmp($val,'5'))){echo "class=\"current\"";}

student101
07-06-2008, 11:18 AM
Nothing seems to make this work without using a different system.

You do understand what I am asking though?

For some reason the menu wont stay highlighted, ever! (even with plain CSS), well... not in my instance.

Cheers

davidj
07-06-2008, 11:32 AM
is it the class which determins whether its selected

student101
07-06-2008, 11:39 AM
Yes

Old way:
Top of page: <?php $page = basename($_SERVER['SCRIPT_NAME']); ?>
5 pages, ie: index.php, faq.php, etc...
<li><a href="index.php" <?php if ($page == 'index.php') { ?>class="current"<?php } ?>><b>HOME</b></a></li>
New way:
Top of page: <?php $page = basename($_SERVER['SCRIPT_NAME']); ?>
1 page, ie: index.php
1 x database table with page titles and data
Correction here:
<?php do { ?>
<li><a href="?pid=<?php echo $row_rsnav['pid']; ?>" <?php if ($page == 'wont work here') { ?>class="current"<?php } ?>><?php echo strtoupper($row_rsnav['pname']); ?></a></li>
<?php } while ($row_rsnav = mysql_fetch_assoc($rsnav)); ?>

student101
07-06-2008, 12:28 PM
Does it make sense?

student101
07-06-2008, 02:01 PM
I am open to any and or all suggestions in making the current link active.

Cheers

davidj
07-06-2008, 03:09 PM
<?php if ($pageid == "5") { echo ?>class="current"<?php } ?>

student101
07-06-2008, 06:19 PM
Fixed:
I used the old method, made a few............. adjustments to the page.
$page = basename($_SERVER['SCRIPT_NAME']);
$dbpage = $page."?pid=".$_GET['pid'];
<>...<>
<li id="home"><a href="?pid=6" <?php if ($dbpage == 'index.php?pid=6') { ?>class="current"<?php } ?>><b>HOME</b></a></li>

Thanks for your help here, I couldn't find a solution so this will do.

Cheers

student101
07-06-2008, 06:21 PM
<?php if ($pageid == "5") { echo ?>class="current"<?php } ?>

I didn't see your answer, till now.
Will test it.

No luck - That was my first choice.
It highlights all the menu items as current.

I think my previous one works out better, I don't think there is a solution for this one.
I don't like to give up but it's not that important - it's just a menu.

Cheers

student101
07-06-2008, 06:52 PM
Just wanted to say thanks, then a message popped up asking if I wanted to contat the administrator, interesting...

Thanks
Cheers