Jump to content

how to display specific pages based upon date?


hls1242

Recommended Posts

First off, im very new to php, so feel free to rip me a new one if I say something stupid. I did a search but didn't find what I was looking for, or I didn't ask for it the right way.

 

I have a php-based membership site that I want to add a monthly section to. Within the php of the site, there is already a variable that shows their join date. What I would like to do is have some sort of switch statement that compares their join date variable to the current date, and displays a different page depending on how many months or days have gone by since they joined.

 

Basically the affect I'm after is this (obviously this is not code of any sort)

 

"current date" minus "join date" = XXX

if XXX under 30 days display : first_month_content.html

if XXX between 30-60 days display : second_month_content.html

if XXX between 61-90 days display : third_month_content.html

if XXX between 91-120 days display : fourth_month_content.html

 

I'm sure there is a very simple/easy way to code this with PHP, but I don't know enough to do it.

 

Thanks for any help!

I don't know what kind of format your membership joined date is so I assume it's a datetime field or a string.

 

<?php
$now = time();
$joined = strtotime($joindate);
$diff = $now - $joined;
$days = intval((floor($diff/86400)));

switch ($days) {
case ($days < 30):
  include('first....html');
  break;
case ($days >= 30 && $days < 60 ):
  include('second....html');
  break;

case ($days >= 60 && $days < 90 ):
  include('third....html');
  break;

....
}
?>

Now of course with this you would have to type in the specific files and numbers manually everytime you want to change it.

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.