On Mon, 10 Jan 2005 13:08:28 -0500, John Taylor-Johnston
<[EMAIL PROTECTED]> wrote:
> Hi,
> I would like some help to improve this script. I'm a teacher with a schedule 
> of 17 weeks.
> Instead of using if(date("Y-m-d") >= $week3)  I would like to do a "for i = 1 
> to 17" and if the current date date("Y-m-d") = week[i] I would like to echo 
> "This is week $week[i]";
> 
> Can someone show me how please?
> 
> <?php
> #old code:
> $week1 = "2005-01-17";
> $week2 = "2005-01-24";
> ...
> $week17 = "2005-05-09;
> 
> if(date("Y-m-d") >= $week3)
> {
> echo "this is week 3");
> }
> ?>
> 

You're actually pretty close.  What I would do is remove the dashes
from the equation and make that date a unique number.  The advantage
of the date format you're using is that the date represented as a
number will always be sequential.  So, if you do this:

$week1 = "20050110";
$week2 = "20050117";
$week3 = "20050124";

if(date("Ymd") >= $week1)
{
echo "this is week 1";
}

Now you'll have to create your logic in reverse, so that it will
trigger the latest date first, because every date from now until week
17 will be greater than $week1.  So, something like:

if (date("Ymd") >= $week17)
{
     echo "This is week 17";
}
elseif (date("Ymd") >= $week16)
{
    echo "This is week 16";
}

etc.  

Does that make sense?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to