parboy Posted September 7, 2010 Share Posted September 7, 2010 I am trying to select text to display on condition of the current date. I've set a Unix timestamp for the current date: <?php $todays_date = date("Y-m-d"); $today = strtotime($todays_date); ?> Next I test for the first condition. I want the text to appear for 2 weeks then terminate: <?php $exp_date = "2011-05-09"; $expiration_date = strtotime($exp_date); $start_date = strtotime("-14 days", $expiration_date); if ($start_date < $today && $expiration_date > $today) { echo "<h2>Special Event #1</h2>"; } elseif { At this point, I want to set the exp_date for the next event and test again, but I don't know how to do it. The techniques I've tried appear to evaluate as false and display the default text which follows the final "else": } else { echo "<h2>Default Text</h2>"; } ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted September 7, 2010 Share Posted September 7, 2010 How you get the events is relevant here. Can you show some more of your code? Quote Link to comment Share on other sites More sharing options...
parboy Posted September 7, 2010 Author Share Posted September 7, 2010 That's pretty much the code I've written. The conditional statements are all based on the event's expiration date which is defined: $exp_date = "2011-05-09"; The special text is also defined for each event: echo "<h2>Special Event #1</h2>"; I had intended to repeat the conditional test for each event with a string of "elseif" conditional statements, but it doesn't work. I think one problem is how to reset the exp_date within a conditional statement. Quote Link to comment Share on other sites More sharing options...
btherl Posted September 7, 2010 Share Posted September 7, 2010 The question of how to reset $exp_date is closely tied into where $exp_date comes from. Do you have an array of events? Are you getting them from the database? How about something like this: $events = array( array( 'exp_date' => '2010-08-01', 'start_date' => '2010-07-01', 'name' => 'July Madness', ), array( 'exp_date' => '2010-09-01', 'start_date' => '2010-08-01', 'name' => 'August Apathy', ), ); foreach ($events as $event) { $event_exp_date = $event['exp_date']; $event_start_date = $event['start_date']; $event_name = $event['name']; if (...) { } elseif ( ...) { } } Then all your conditions can go in there. The event variables will be set to the ones for each event in turn. Quote Link to comment Share on other sites More sharing options...
parboy Posted September 8, 2010 Author Share Posted September 8, 2010 Thanks, I was going in that direction, i.e., defining the variables for each event and then stringing the conditional statements. My skills with arrays are limited, so it was helpful to see how you handled that aspect. It's working now. 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.