dadamssg Posted April 4, 2009 Share Posted April 4, 2009 i have a date and time selection list that the user can pick the the month, day, year, hour, and minutes and a am/pm selection. I want to create an update script where the user can update the datetime if the event changes. Does anyone know a logical way to get that datetime out of the db and then output it in that datetime selection list? example would be like april 4 2009, 4:15 pm and then in the dropdown box for months April would be selected, 4 would be selected in the day dropdown menu, 2009 for the year selection, 4 for the hours box, 15 for the minutes selection, and then pm selected for the am/pm radio buttons...i think i could SLOWLY figure out how to do it for everything except the am/pm...does anyone have any suggestions? Link to comment https://forums.phpfreaks.com/topic/152480-datetime-to-be-outputted-as-selected-in-a-date-selection-list/ Share on other sites More sharing options...
flyhoney Posted April 4, 2009 Share Posted April 4, 2009 How are the date and time stored in the database? Link to comment https://forums.phpfreaks.com/topic/152480-datetime-to-be-outputted-as-selected-in-a-date-selection-list/#findComment-800804 Share on other sites More sharing options...
dadamssg Posted April 4, 2009 Author Share Posted April 4, 2009 they're stored as datetimes, so they look like this in the db 2010-07-07 17:25:00 Link to comment https://forums.phpfreaks.com/topic/152480-datetime-to-be-outputted-as-selected-in-a-date-selection-list/#findComment-800816 Share on other sites More sharing options...
dadamssg Posted April 4, 2009 Author Share Posted April 4, 2009 k ive grabbed each value like this $mo = date("M", strtotime($row['start'])); $da = date("j", strtotime($row['start'])); $yr = date("Y", strtotime($row['start'])); $hr = date("g", strtotime($row['start'])); $mi = date("i", strtotime($row['start'])); $ap = date("a", strtotime($row['start'])); and i have this for building the selection list /* build selection list for the month */ $todayMO = $mo; //get the month selected echo "<select name='smonth'>\n"; for ($n=1;$n<=12;$n++) { echo "<option value=$n\n"; if ($todayMO == $n) { echo " selected"; } echo "> $smonth[$n]\n"; } echo "</select>\n"; but it doesn't select anything...just has january selected always...any help? i have the variables defined on my update_form script but i am including the file that builds the selection list. Link to comment https://forums.phpfreaks.com/topic/152480-datetime-to-be-outputted-as-selected-in-a-date-selection-list/#findComment-800870 Share on other sites More sharing options...
unrelenting Posted April 4, 2009 Share Posted April 4, 2009 k ive grabbed each value like this $mo = date("M", strtotime($row['start'])); $da = date("j", strtotime($row['start'])); $yr = date("Y", strtotime($row['start'])); $hr = date("g", strtotime($row['start'])); $mi = date("i", strtotime($row['start'])); $ap = date("a", strtotime($row['start'])); and i have this for building the selection list /* build selection list for the month */ $todayMO = $mo; //get the month selected echo "<select name='smonth'>\n"; for ($n=1;$n<=12;$n++) { echo "<option value=$n\n"; if ($todayMO == $n) { echo " selected"; } echo "> $smonth[$n]\n"; } echo "</select>\n"; but it doesn't select anything...just has january selected always...any help? i have the variables defined on my update_form script but i am including the file that builds the selection list. Try this: <?php /* build selection list for the month */ $todayMO = $mo; //get the month selected echo "<select name='smonth'>\n"; for ($n=1;$n<=12;$n++) { if ($todayMO == $n) { echo '<option value=" . $n . " selected>' . $smonth[$n] . '</select>'; } else { echo '<option value=" . $n . ">' . $smonth[$n] . '</select>\n'; } } ?> Link to comment https://forums.phpfreaks.com/topic/152480-datetime-to-be-outputted-as-selected-in-a-date-selection-list/#findComment-800939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.