|
|
|
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.
p.s. I really love Weberdev -- it rules PHP like Odin rules Valhalla!
call the function like this:
<?PHP
stamper($previous_value);
?>
__________________________________
<?PHP
function stamper($previous_value) {
// your constants
$form_name = "form1";
$store_stamp_field = "datestamp";
// looks for previous 14 char stamp or defaults to now
if (!$previous_value) {
$my_stamp = date("YmdHis");
} else {
$my_stamp = $previous_value;
}
// parses the timestamp & digests it into useful variables
$year=substr($my_stamp,0,4);
$month=substr($my_stamp,4,2);
$day=substr($my_stamp,6,2);
$hour=substr($my_stamp,8,2);
$minute=substr($my_stamp,10,2);
$second=substr($my_stamp,12,2);
// here you can set your ("starting value", "range") for each
$year_range = array("2000","11");
$month_range = array("01","12");
$day_range = array("01","31");
$hour_range = array("00","24");
$minute_range = array("00","60");
$second_range = array("00","60");
$names = array("month","day","year","hour","minute","second");
$names_for_stamp = array("year","month","day","hour","minute","second");
// this drops in some javascript to do the onChange event handler for each select list
echo "<script language=\"JavaScript\">\n";
echo "function adj_timestamp () {\n";
echo "var each_field = new Array(" . count($names) . ");\n";
for ($i=0;$i<count($names);$i++) {
echo "each_field[" . $i . "] = document." . $form_name . "." . $names_for_stamp[$i] . ".options
[document." . $form_name . "." . $names_for_stamp[$i] . ".selectedIndex].value;";
}
echo "var timestamp = ";
for ($i=0;$i<count($names);$i++) {
if ($i!=(count($names)-1)) {
echo "each_field[" . $i . "] + ";
} else {
echo "each_field[" . $i . "];\n";
}
}
echo "document." . $form_name . "." . $store_stamp_field . ".value = timestamp;\n";
echo "}\n";
echo "</script>\n";
// this creates the selects and add the JS event handler
for ($i=0;$i<count($names);$i++) {
echo "<select name=\"$names[$i]\" onChange=\"adj_timestamp();\">\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 "<option value=\"$each_val\"$selected>$each_val</option>\n";
}
echo "</select>\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 "<input type=\"text\" name=\"$store_stamp_field\" value=\"$the_stamp\">\n";
}
?>
|
|
| Pull Down Surfing - Surf on Change Categories : Java Script, MySQL, HTML and PHP, PHP, Databases | | | OverEasy - PHP generated JavaScript to do mouseovers on
your pages. Modify one file and one function does it all
for you! Categories : PHP, Java Script, HTML and PHP, MySQL | | | AJAX Data Grid System using php and mysql. A complete login system with the ability to display data in a grid using ajax. Add , update and delete the records without reloading the page. Categories : PHP, AJAX, Databases, MySQL, Java Script | | | Amazon book cover handling Categories : HTML and PHP, PHP, MySQL, Ecommerce | | | Complete, simple working example of login screen and check on a unique page using php functions, cookies and mysql database. Categories : PHP, Cookies, MySQL, HTML and PHP, Authentication | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | Validator 98 - a PHP-script to generate form-validation-code in JavaScript. Categories : Complete Programs, Java Script, PHP, HTML and PHP | | | Functions for loading images into a MySQL database and displaying them. Categories : Graphics, HTML and PHP, MySQL, PHP, Databases | | | dynamic table columns Categories : PHP, HTML and PHP, Arrays, Databases, MySQL | | | Dynamically generated pop-ups (Select items) Categories : PHP, HTML and PHP, MySQL, Databases | | | Complex paging with no resultset limit Categories : PHP, MySQL, Databases, Output Control, HTML and PHP | | | phpFormGenerator for Dynamic Form Generation from MySQL Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | A Complete table(ADD,EDIT,VIEW,DELETE) management System PHP,MYSQL, JAVASCRIPT Categories : PHP, MySQL, Java Script, Databases | |
|
|