Jump to content

Include content help


spacepoet

Recommended Posts

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

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;
}

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.