scarhand Posted July 18, 2008 Share Posted July 18, 2008 i have this code: <?php echo '<td class="' . ($page_title1 == 'Home') ? 'menutab2' : 'menutab1' . '"><a href="/"><span><span>Home</span></span></a></td>'; ?> i want it to echo "menutab#" depeding on if the $page_title1 variable is 'Home' or not. when i look at the source code, it is only echoing "menutab2", instead of "<td class="menutab2"><a href="/"><span><span>Home</span></span></a></td>" like it should im sure its simple, help? Link to comment https://forums.phpfreaks.com/topic/115343-solved-simple-if-statement-inside-echo-not-working/ Share on other sites More sharing options...
btherl Posted July 18, 2008 Share Posted July 18, 2008 Try this: <?php echo '<td class="' . ($page_title1 == 'Home' ? 'menutab2' : 'menutab1') . '"><a href="/"><span><span>Home</span></span></a></td>'; ?> The problem was with the brackets. Link to comment https://forums.phpfreaks.com/topic/115343-solved-simple-if-statement-inside-echo-not-working/#findComment-593068 Share on other sites More sharing options...
scarhand Posted July 18, 2008 Author Share Posted July 18, 2008 Thanks, i ended up going this route though: <?php echo '<td class="'; echo ($page_title1 == 'Home') ? 'menutab2' : 'menutab1'; echo '"><a href="/"><span><span>Home</span></span></a></td>'; ?> Link to comment https://forums.phpfreaks.com/topic/115343-solved-simple-if-statement-inside-echo-not-working/#findComment-593116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.