spacepoet Posted March 8, 2011 Share Posted March 8, 2011 Hi: I have this code that - when added to a page - works fine: <div class=\"<?php echo (time() <= strtotime('4/17/2011 2:00:00 AM')) ? 'myUpcoming' : 'myPassed'; ?>\"> <span class=\"myGameDate\">April 16:</span> <span class="myGameDateRed">Home</span> vs Baltimore </div> It's a schedule that will display one CSS style before the date, and another CSS style after the date. Works fine on the homepage. I am trying to add it to an include navigation file, so I can add it to all the pages like this: myNav.php function spSchedule() { $spSchedule = " <div class=\". echo time() ." <= strtotime("4/17/2011 2:00:00 AM") ? \"myUpcoming\" : \"myPassed\"; .\"> <span class=\"myGameDate\">April 16:</span> <span class=\"myGameDateRed\">Home</span> vs Baltimore </div> "; return $spSchedule; } myPage.php: <?php include('include/myNav.php'); ?> ... <?php echo spSchedule(); ?> What it is doing is writing "myUpcoming" to the page, and that's it. What am I missing on this, please? Link to comment https://forums.phpfreaks.com/topic/230040-include-content-help/ Share on other sites More sharing options...
mikecampbell Posted March 8, 2011 Share Posted March 8, 2011 You can't use strings like that. Try this instead. function spSchedule() { $x = (time() <= strtotime('4/17/2011 2:00:00 AM')) ? 'myUpcoming' : 'myPassed'; $spSchedule = " <div class=\"". $x ."\"> <span class=\"myGameDate\">April 16:</span> <span class=\"myGameDateRed\">Home</span> vs Baltimore </div> "; return $spSchedule; } Link to comment https://forums.phpfreaks.com/topic/230040-include-content-help/#findComment-1184778 Share on other sites More sharing options...
spacepoet Posted March 8, 2011 Author Share Posted March 8, 2011 Excellent! Thanks works perfectly. One question: How would I add more games? Like this: ... $x = (time() <= strtotime('4/17/2011 2:00:00 AM')) ? 'myUpcoming' : 'myPassed'; $x2 = (time() <= strtotime('5/17/2011 2:00:00 AM')) ? 'myUpcoming' : 'myPassed'; ... <div class=\"". $x ."\"> <span class=\"myGameDate\">April 16:</span> <span class=\"myGameDateRed\">Home</span> vs Baltimore Nighthawks </div> <div class=\"clearAndPad\"></div> <div class=\"". $x2 ."\"> <span class=\"myGameDate\">May 16:</span> <span class=\"myGameDateRed\">Home</span> vs San Diego </div> <div class=\"clearAndPad\"></div> ... Is that the best way? Link to comment https://forums.phpfreaks.com/topic/230040-include-content-help/#findComment-1184800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.