[thelist] Update styles based on date with PHP?

Max Schwanekamp lists at neptunewebworks.com
Mon Sep 18 13:26:23 CDT 2006


> From: Jono 
> I have a number of events listed in an HTML table:
> <table>
>         <tr>
>           <td class="format"><a href="#" 
> class="external">Talk Like a Pirate Day</a></td>
>           <td>September 19</td>
>           <td class="last">Charleston, SC</td>
>         </tr> ...
> </table>
> 
> I would like to apply the style - .past { text-decoration: 
> line-through; } -  to the events that have already 
> occurred/past. 

I assume that the calendar items are being generated by PHP too, right?
Assuming straight PHP + HTML, where each row is coming from, say an array of
"event" objects, then you would just need to modify your php to compare the
dates and add the class.  I'd put it on the <tr> so you can style all the
children <td>'s if need be.

<?php 
foreach($events as $event) {
?>
<tr<?php echo(strtotime($event->date) < time() ? 'class="past"' : ''); ?>>
	...
</tr>
<?php	
}
?>

The strtotime() is only if $event->date is not already in unix timestamp
format.  I'm guessing your issue is more complex than this solution, so
maybe some source code would help get a more direct answer.

-- 
Max Schwanekamp
NeptuneWebworks.com
 

 





More information about the thelist mailing list