下一篇 » « 上一篇

Figure 18-11: DateSelector

作者:semirock    时间:2009-07-07    来源:http://444p.com    点击:24196    本文共1篇文章 字体:[ ]

Figure 18-11: DateSelector

<HTML>
<HEAD>
<TITLE>Figure 18-11</TITLE>
</HEAD>
<BODY>
<?
/*
** create three selectors for date
*/
function DateSelector($name, $date)
{
$MonthName = array(1=>"January", "February", "March",
"April", "May", "June", "July", "August",
"September", "October", "November", "December");

if($date == "")
{
$date = time();
}

//Month
print("<SELECT NAME=\"" .
$name . "Month\">\n");

for($currentMonth = 1;
$currentMonth <= 12;
$currentMonth++)
{
print("<OPTION VALUE=\"$currentMonth\"");
if(date("m", $date) == $currentMonth) www.444p.com
{
print(" SELECTED");
}
print(">");
print($MonthName[$currentMonth]);
print("\n");
}
print("</SELECT>\n");

//Day
print("<SELECT NAME=\"" .
$name . "Day\">\n");
for($currentDay = 1;
$currentDay <= 31;
$currentDay++)
{
print("<OPTION VALUE=\"$currentDay\"");
if(date("d", $date) == $currentDay)
{
echo " SELECTED";
}
echo ">$currentDay\n";
}
print("</SELECT>\n");

print("<SELECT NAME=\"" .
$name . "Year\">\n");

$startYear = date("Y", $date);

for($currentYear = $startYear - 5; $currentYear <= $startYear+5;$currentYear++) www.444p.com php学习之家
{
print("<OPTION VALUE=\"$currentYear\"");
if(date("Y", $date) == $currentYear)
{
print(" SELECTED");
}
print(">$currentYear\n");
}
print("</SELECT>\n");
}

print("<HTML>\n");
print("<HEAD>\n");
print("<TITLE>Figure 18-11</TITLE>\n");
print("</HEAD>\n");

print("<BODY>\n");

/*
** choose default date
*/
if(isset($SampleMonth))
{
//construct time
$UseDate = mktime(0, 0, 0,
$SampleMonth,
$SampleDay,
$SampleYear);
}
else
{
// use now
$UseDate = time();
}

print("<FORM ACTION=\"18-11.php3\">\n");

DateSelector("Sample", $UseDate);
www.444p.com版权所有


print("<INPUT TYPE=\"submit\">\n");

print("</FORM>\n");

print("</BODY>\n");
print("</HTML>\n");
?>
责任编辑:semirock
发表评论
密码: (游客不需要密码)
记住我【Alt+S 或 Ctrl+Enter 快速提交】

搜索工具


《PHP函数》点击排行