I'm looking to create drop down boxes for a user to select the date and then have it insert what they select for month, day, year, hour, minutes and insert it into mysql. It needs to be organized in a timestamp like so: 2007-02-28 21:06:40
I've created the drop down boxes and it works pretty well:
function selectCurrentDate($currentMonth, $currentDay, $currentYear, $currentHour, $currentMins, $currentSecs)
{
$display = '';
// Month Array
$monthNames = array('January', 'Feburary', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December');
// MaxNumber of days in a month (will need to write more robust code)
$maxDays = 31;
// Start year
$startYear = 2000;
// Display years up to max years
$maxYears = 2050;
// Max hours to display
$maxHour = 12;
// Max minutes to display
$maxMinutes = 59;
// Max seconds to display
$maxSeconds = 59;
// Begin Month select menu
$display .= 'Select event date: <select name="theMonth">';
// Loop through each month
foreach ($monthNames as $myMonth)
{
// If month is equal to $currentMonth passed in, select
if($currentMonth == $myMonth)
$display .= '<option value="'. $myMonth .'" selected>' . $myMonth . '</option>';
else
$display .= '<option value="'. $myMonth .'">' . $myMonth . '</option>';
}
// end select
$display .= '</select> ';
// Begin Day select Menu
$display .= ' <select name="theDay">';
// Loop through the max number of days
for($i = 1; $i < $maxDays; $i++)
{
if($i == $currentDay)
$display .= '<option value="'. $i .'" selected>'. $i.'</option>';
else
$display .= '<option value="'. $i .'">'. $i.'</option>';
}
// end day select
$display .= '</select>';
// Display year select
$display .= ' <select name="theYear">';
// Loop through max number of years
for($i = $startYear; $i <= $maxYears; $i++)
{
if($i == $currentYear)
$display .= '<option value="'. $i .'" selected>'. $i.'</option>';
else
$display .= '<option value="'. $i .'">'. $i.'</option>';
}
$display .= '</select>';
// Begin hour select
$display .= ' <select name="theHour">';
for($h = 1; $h <= $maxHour; $h++)
{
if($h == $currentHour)
$display .= '<option value="'. $h .'" selected>'. $h.'</option>';
else
$display .= '<option value="'. $h .'">'. $h.'</option>';
}
$display .= '</select>';
// Begin minute display
$display .= '<select name="theMinutes">';
for($m = 1; $m <= $maxMinutes; $m++)
{
if($m == $currentMins)
$display .= '<option value="'. $m .'" selected>'. $m.'</option>';
else
$display .= '<option value="'. $m .'">'. $m.'</option>';
}
$display .= '</select>';
// Begin second display
$display .= '<select name="theSeconds">';
for($s = 1; $s <= $maxSeconds; $s++)
{
if($s == $currentSecs)
$display .= '<option value="'. $s .'" selected>'. $s.'</option>';
else
$display .= '<option value="'. $s .'">'. $s.'</option>';
}
$display .= '</select>';
return $display;
}
$curmonth = date('F');
$curday = date('j');
$curyear = date('Y');
$curhour = date('g');
$curmin = date('i');
$cursecs = date('s');
echo selectCurrentDate($curmonth,$curday,$curyear,$curhour,$curmin,$cursecs);
Now how would I organize all the data into a timestamp. Once it's in the form of the timestamp it'll be easy to insert it into mysql. Could I do something like:
$events = mysql_query("INSERT INTO timestamp, DATE_FORMAT(date, '%M %e, %Y %h:%m:%s') as something?
date, FROM calevents") or die(mysql_error());
I don't really get how the options work
Thanks for the suggestions