spacepoet Posted January 27, 2011 Share Posted January 27, 2011 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 More sharing options...
AbraCadaver Posted January 27, 2011 Share Posted January 27, 2011 Pretty similar, you just need to familiarize yourself with the syntax and needed functions: <?php if(time() <= strtotime('2/26/2011 2:00:00 AM')): ?> EVENT LISTING 1 <?php endif; ?> Link to comment https://forums.phpfreaks.com/topic/225891-autoremoval-by-date-with-php/#findComment-1166224 Share on other sites More sharing options...
AbraCadaver Posted January 27, 2011 Share Posted January 27, 2011 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. Link to comment https://forums.phpfreaks.com/topic/225891-autoremoval-by-date-with-php/#findComment-1166228 Share on other sites More sharing options...
spacepoet Posted January 27, 2011 Author Share Posted January 27, 2011 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? Link to comment https://forums.phpfreaks.com/topic/225891-autoremoval-by-date-with-php/#findComment-1166238 Share on other sites More sharing options...
AbraCadaver Posted January 27, 2011 Share Posted January 27, 2011 Looks right. You could also do this: <div class="<?php echo (time() <= strtotime('2/26/2011 2:00:00 AM')) ? 'active' : 'expired'; ?>"> EVENT LISTING 1 </div> Link to comment https://forums.phpfreaks.com/topic/225891-autoremoval-by-date-with-php/#findComment-1166241 Share on other sites More sharing options...
spacepoet Posted January 28, 2011 Author Share Posted January 28, 2011 Very nice! These will be helpful solutions for me. Appreciate the help. Link to comment https://forums.phpfreaks.com/topic/225891-autoremoval-by-date-with-php/#findComment-1166312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.