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? Quote Link to comment 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; } Quote Link to comment 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? Quote Link to comment 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.