ChrisML123 Posted October 14, 2008 Share Posted October 14, 2008 I'm trying to write a menu that will automatically change the colour of the active page to red. In this example below, $page is recieved through $_GET, meaning that, in the case of the current page being about.php, $page == "about": The first case statement echos a non clickable red menu item. The second a standard white link. Sadly it doesn't work, either giving me duplicates, or no items at all. Any ideas? switch ($page) { case "about": echo ('<p align="right" class="style2" font color="#ff0000">about the artist</p><p align="right" class="style3">'); echo ('<p align="right" class="style2"><a href="?page=about">about the artist</a></p><p align="right" class="style3">'); case "bandw": echo ('<span class="style3on">b&w</span><br>'); echo ('<a href="?page=bandw">b&w</a><br>'); case "colour": echo ('<span class="style3on">colour</span><br>'); echo ('<a href="?page=colour">colour</a><br>'); } EG 1. where $page=="main", no menus appear at all EG 2. where $page=="about", I get two of every item. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/128304-solved-coloured-menus/ Share on other sites More sharing options...
Lamez Posted October 14, 2008 Share Posted October 14, 2008 another problem solved with session variables! set each page with a session variable that is unique from the others, example page name. Then have a custom function or tons of if statements. You could do if this session var is = to page name then font color is red, else if and continue! Quote Link to comment https://forums.phpfreaks.com/topic/128304-solved-coloured-menus/#findComment-664640 Share on other sites More sharing options...
CroNiX Posted October 14, 2008 Share Posted October 14, 2008 Well, you forgot your break statement at the end of each case statement. Quote Link to comment https://forums.phpfreaks.com/topic/128304-solved-coloured-menus/#findComment-664644 Share on other sites More sharing options...
genericnumber1 Posted October 14, 2008 Share Posted October 14, 2008 There are a lot of problems with your switch statement... try this... switch ($page) { case "about": echo ('<p align="right" class="style2" font color="#ff0000">about the artist</p><p align="right" class="style3">'); echo ('<p align="right" class="style2"><a href="?page=about">about the artist</a></p><p align="right" class="style3">'); break; case "bandw": echo ('<span class="style3on">b&w</span><br>'); echo ('<a href="?page=bandw">b&w</a><br>'); break; case "colour": echo ('<span class="style3on">colour</span><br>'); echo ('<a href="?page=colour">colour</a><br>'); break; default: echo "No options are in the switch statement for this value"; } Quote Link to comment https://forums.phpfreaks.com/topic/128304-solved-coloured-menus/#findComment-664651 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.