Hi
I'm trying to write a jump menu that displays all the days in the current 3 months
i found a bit of code on the web that outputs consecutive days and I'm trying to adapt it for my purposes
I've almost got it to work - i use explode() to chop up the $timestamp variable into an array then output three of those elements in my jump menu
the problem is that when it gets to the 10th day of each month all the array elements shift sideways by 1 index - i really can't see why this should be
here's the code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>menu test</title>
<script type="text/javascript">
<!--
function setStartDate(y,m,d){
document.forms["spec_form"].elements["_START_DATE"].value = d+"-"+m+"-"+y;
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<form name="form1" id="form1">
<select name="menu1" onchange="MM_jumpMenu('parent',this,0)">
<?php
define ('DATE_ENUM_DAY', 1);
define ('DATE_ENUM_MONTH', 2);
/*
* enumerate a date and call a user function
* dateBeginTS, dateEndTS : Timestamp date
* callbackfunc : name of the php function to callback
* this cb function receive 2 parameters : the current enumerated date (timestamp) and the $param parameter
* step : DATE_ENUM_DAY or DATE_ENUM_MONTH
* param : a user parameter
*/
function date_enumeration($dateBeginTS, $dateEndTS, $callbackfunc, $step, $param = NULL)
{
$cur = $dateBeginTS;
while($cur <= $dateEndTS)
{
$callbackfunc($cur, $param);
if ($step == DATE_ENUM_DAY)
{
$cur = mktime(
date('h', $cur),
date('i', $cur),
date('s', $cur),
date('m', $cur),
date('d', $cur) + 1,
date('Y', $cur));
}
else if ($step == DATE_ENUM_MONTH)
{
$cur = mktime(
date('h', $cur),
date('i', $cur),
date('s', $cur),
date('m', $cur) + 1,
date('d', $cur),
date('Y', $cur));
}
else
{
die ('No step specified');
}
}
}
/// SAMPLE USAGE
function cb_test($timestamp, $param)
{
//echo date('r', $timestamp), ' ', $param, "<br>\n";
$date_parts = explode(" ",date('r', $timestamp));
echo "<option>".$date_parts[2]."-".$date_parts[3]."-".$date_parts[4]."</option><br>\n";
}
date_enumeration(
mktime(0,0,0,1,1,2006),
mktime(0,0,0,4,1,2006),
'cb_test',
DATE_ENUM_DAY
);
?>
</select>
</form>
</body>
</html>
can anyone see what i need to do here ?
and btw can i just ask for your opinion on another simple matter ? : what's the best format for saving dates in a MySQL db to make searching by date as simple as possible ? is it better to enter the day, month, year in separate fields ?
thanks for any help you can give !