geektasic Posted April 14, 2009 Share Posted April 14, 2009 Hey all, I'm using a css rollover technique which shifts the background image of my navigation items. I'm also using php if statement to implement my sub menus. Here's the code my sub menu uses. The id is controlled via php switch. <li><a id="<? echo $rollover_id; ?>" class="navigation_class" href="index.php?linkn"><span class="navigation_span">Link</span></a></li> <!-- Sub menu--> <? if ( $sub_menu == "true" ) { echo " <li><a id=\"button_rollover\" class=\"navigation_class\" href=\"index.php?link1\"><span class=\"navigation_span\">Link 1</span></a></li> <li><a id=\"button_rollover\" class=\"navigation_class\" href=\"index.php?link2\"><span class=\"navigation_span\">Link 2</span></a></li> <li><a id=\"button_rollover\" class=\"navigation_class\" href=\"index.php?link3\"><span class=\"navigation_span\">Link 3</span></a></li> "; } ?> Within the submenu, is it possible to insert an echo so I can define my rollover for the submenu id? I.e. can I replace "button_rollover" with $rollover_id? I'd like to do this so I can make the button active when you're on that page. I hope this makes sense. I'm quite new to PHP, so thank you for your patience. S Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/ Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 change it to this... <li><a id="<?php echo $rollover_id; ?>" class="navigation_class" href="index.php?linkn"><span class="navigation_span">Link</span></a></li> <!-- Sub menu--> <?php if ( $sub_menu == "true" ) { echo "<li><a id=\"".$rollover_id."\" class=\"navigation_class\" href=\"index.php?link1\"><span class=\"navigation_span\">Link 1</span></a></li>"; echo "<li><a id=\"".$rollover_id."\" class=\"navigation_class\" href=\"index.php?link2\"><span class=\"navigation_span\">Link 2</span></a></li>"; echo "<li><a id=\"".$rollover_id."\" class=\"navigation_class\" href=\"index.php?link3\"><span class=\"navigation_span\">Link 3</span></a></li>"; } ?> Regards, ACE Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809355 Share on other sites More sharing options...
geektasic Posted April 14, 2009 Author Share Posted April 14, 2009 Strange, it doesn't seem to work. When I use that technique, it prints the ID as blank in the html. Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809368 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 with the link at the very top does it display it in the link? Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809370 Share on other sites More sharing options...
geektasic Posted April 14, 2009 Author Share Posted April 14, 2009 In the html, using your technique, it reads in the HTML: <li><a id="" class="navigation_class" href="index.php?link1"><span class="navigation_span">Link 1</span></a></li> Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809377 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 then $rollover_id doesn't appear to be set. add to your script some where... <?php if(!isset($rollover_id)) { echo "rollover_id is not set!"; } ?> Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809379 Share on other sites More sharing options...
geektasic Posted April 14, 2009 Author Share Posted April 14, 2009 Good point! I hadn't set $rollover_id! Thank you for your help. One last question... with what you mentioned about the !isset, where exactly would I place that in my current sub menu code? It's a useful little bit of code which I'd like to play with. Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809397 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 you can do something like... <?php if(isset($rollover_id)) { ?> <li><a id="<?php echo $rollover_id; ?>" class="navigation_class" href="index.php?linkn"><span class="navigation_span">Link</span></a></li> <!-- Sub menu--> <?php if ( $sub_menu == "true" ) { echo "<li><a id=\"".$rollover_id."\" class=\"navigation_class\" href=\"index.php?link1\"><span class=\"navigation_span\">Link 1</span></a></li>"; echo "<li><a id=\"".$rollover_id."\" class=\"navigation_class\" href=\"index.php?link2\"><span class=\"navigation_span\">Link 2</span></a></li>"; echo "<li><a id=\"".$rollover_id."\" class=\"navigation_class\" href=\"index.php?link3\"><span class=\"navigation_span\">Link 3</span></a></li>"; } } else { echo "No Available Links!"; } ?> Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809399 Share on other sites More sharing options...
geektasic Posted April 14, 2009 Author Share Posted April 14, 2009 Perfect! Thank you for all your help Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809408 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 you're welcome Link to comment https://forums.phpfreaks.com/topic/153983-solved-echo-within-echo/#findComment-809410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.