RE: [PHP] PHP Auto-Date Select Box
| From: | Matt Schroebel | Date: | Fri, 04 Apr 2003 14:25:01 +0000 |
| Subject: | RE: [PHP] PHP Auto-Date Select Box | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-142337@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Jay Fitzgerald [mailto:jayfitz@bayou.com]
> Sent: Friday, April 04, 2003 9:17 AM
> Subject: [PHP] PHP Auto-Date Select Box
>
>
> Does anyone know how I can make a PHP form select box that
> has the dates in
> it for the next 7 days including today and the remaining days
> from this week?
>
> eg:
> <SELECT NAME="date">
> <OPTION VALUE="2003-04-05">Friday, April 5
> <OPTION VALUE="2003-04-06">Saturday, April 6
> <OPTION VALUE="2003-04-07">Sunday, April 7
> <OPTION VALUE="2003-04-08">Monday, April 8
> <OPTION VALUE="2003-04-09">Tuesday, April 9
> <OPTION VALUE="2003-04-10">Wednesday, April 10
> <OPTION VALUE="2003-04-11">Thursday, April 11
> <OPTION VALUE="2003-04-12">Friday, April 12
> <OPTION VALUE="2003-04-05">Saturday, April 13
> <OPTION VALUE="2003-04-05">Sunday, April 14
> </SELECT>
I'd use date() and time() and a function such as
Function buildSelect($howMany,$name) {
$str = "<SELECT NAME=\"$name\">\n";
$t = time();
For (i=0;$i<$howMany;$i++) {
$str .= '<OPTION VALUE="';
$str .= date('your numeric format string',$t);
$str .= '">'
$str .= date('your verbose format string',$t) . "\n";;
$t += 86400;
}
$str .= "/SELECT>\n";
return $str;
}