This PHP function creates dropdown select lists for time and date that you can
change, outputs a 14 char MySQL timestamp in a text field
Enjoy this - I'm sure it could be more elegant, but I couldn't find something like this anywhere
else. Pull your hair out on more important programming problems! If you like it, or improve
upon it, drop me a line.
call the function like this:
\n";
echo "function adj_timestamp () {\n";
echo "var each_field = new Array(" . count($names) . ");\n";
for ($i=0;$i\n";
// this creates the selects and add the JS event handler
for ($i=0;$i\n";
$this_one = ${"$names[$i]" . "_range"};
for ($k=0;$k<$this_one[1];$k++) {
$each_val = $this_one[0]+$k;
if (strlen($each_val)<2) {
$each_val = sprintf("%02d", $each_val);
}
if (${"$names[$i]"}==$each_val) {
$selected=" selected";
} else {
$selected="";
}
echo "\n";
}
echo "\n";
}
//this creates the initial timestamp
$the_stamp = $year . $month . $day . $hour . $minute . $second;
//this holds the dynamic timestamp value, make it hidden once you get the hang of how it all
works
echo "\n";
}
?>