Jump to content

AutoRemoval by Date with PHP


spacepoet

Recommended Posts

Hello everyone:

 

I have 2 questions.

 

When I do ASP programming and want to have an event be automatically removed from a webpage once the date has passed, I use a little code snippet like this:

<% If Now() <= #2/26/2011 2:00:00 AM# Then %>

EVENT LISTING 1

<% End If %>
Removes EVENT LISTING 1 after Feb. 26, 2011 at 2AM



<% If Now() <= #3/26/2011 2:00:00 AM# Then %>

EVENT LISTING 2

<% End If %>
Removes EVENT LISTING 2 after Mar. 26, 2011 at 2AM

 

1 - How can I this with PHP?

 

2 - How might I be able to have the EVENT be listed in red before the event, but once it has passed I would like it to be listed as gray (like a grayed-out effect)? Somehow write a stylesheet tag that reacts off of the date?

 

There is no admin panel for doing this and won't be for this project. I just want to have the code on the Events.php page.

 

Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/225891-autoremoval-by-date-with-php/
Share on other sites

Sorry for forgetting #2. Probably lot's of ways to do the color thing but here's one:

 

<?php $class = (time() <= strtotime('2/26/2011 2:00:00 AM')) ?  'active' : 'expired'; ?>

<div class="<?php echo $class; ?>">
EVENT LISTING 1
</div>

 

BTW, my first post used the alternative syntax which is closer to ASP and this post uses a ternary operator instead of an if.

Thank you!

 

The first one makes sense - it's just getting firmilar with the syntax that sometimes trips me up.

 

The 2nd one:

 

So, I should list it like this:

<html>
<style>

.active
{
color: #f00;
}

.expired
{
color: #ccc;
}
</style>
...

<?php $class = (time() <= strtotime('2/26/2011 2:00:00 AM')) ?  'active' : 'expired'; ?>

<div class="<?php echo $class; ?>">
EVENT LISTING 1

</div>


<?php $class = (time() <= strtotime('3/26/2011 2:00:00 AM')) ?  'active' : 'expired'; ?>

<div class="<?php echo $class; ?>">
EVENT LISTING 2

</div>

...
</html>

 

 

Looks right to me, no?

 

 

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.