Jump to content

datetime to be outputted as selected in a date selection list


dadamssg

Recommended Posts

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?

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.

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';
   }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.