Lodius2000 Posted June 3, 2008 Share Posted June 3, 2008 this should automatically select the correct hour to display based on the real time, so that I dont have to set it manually it is part of a larger script that I may sometimes have to change the date, but i would like it to default to the actual time so that i dont have to mess with it the majority of the time <?php $defaults = array('hour' => date('g')); $hours = array(); for ($hour = 1; $hour <= 12; $hour++) { $hours[$hour] = $hour;} //print a select menu function input_select($element_name, $selected, $options, $multiple = false){ //print out the <select> tag print '<select name="' . $element_name; // if multiple choices are permitted, add the multiple attribute // and add a [] to the end of the tag name if ($multiple){ print '[]" multiple="multiple'; } print '">'; //set up the list of things to be selected $selected_options = array(); if ($multiple) { foreach ($selected[$element_name] as $val){ $selected_options[$val] = true; } } else { $selected_options[ $selected[$element_name] ] = true; } //print out the <option> tags foreach ($options as $option=>$label) { print '<option value="' . htmlentities($option) . '"'; if ($selected_options[$option]){ print ' selected="selected"'; } print '>' . htmlentities($label) . '</option>'; } print '</select>'; } input_select('hour',$defaults,$hours); ?> for some reason during the 11 am hour it was using 1 as selected, now during the noon hour it is using 2, and not included in this example is an ampm selector, in the script, it has shown am during both hours. on top of that on my website print date('r'); Tue, 03 Jun 2008 14:28:00 -0400 the time is currently 1228 in my timezone (mountain) thanks in avance Link to comment https://forums.phpfreaks.com/topic/108575-why-doesnt-this-work-date-question/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.