nadalia Posted March 16, 2006 Share Posted March 16, 2006 I took over a project that was left behind by a student. The student has defined a table to contain the date range selection that allows the user to pick the range of data to display. Now what I need to do is to add time range selection (from 9am to 10pm) in the table so that the user can select time in addition to date range. Also at the very end of the following code, I also need to format the time to be ready by mysql. Can anybody show me how to add time to the following code?I'd really appreciate!!-----------------------------------------------------------------------------------------------------------------function DisplayDateTable($choice){// this function defines a table to contain the date range selection that allows the user to// pick the range of data to display. This table will be a part of the input form that takes also// the query selection from the user e.g. Activity statistics.// the argument choice is used to specify the default option in the date range selection section.// when "choice" is 0, the current month, year will be selected by default for the start date and// the current day will be selected by default for the end date. when "choice" is 1, the last date// selected by the user will be the default when the web page reloads. echo "<br><table align='center'><tr>"; // display the From and To for the date range. echo "<td width='120' align='center'><strong>Filter records from</strong></td>"; echo "<td align='center' width='60'><select name='StartYear'>"; for ($StartYear = 2005; $StartYear < 2008; $StartYear++) { echo $StartYear; if (($StartYear == date("Y")) && ($choice == 0)) echo "<option value='".$StartYear."' selected>".$StartYear."</option>"; elseif ($StartYear == $_POST['StartYear'] && $choice == 1) echo "<option value='".$StartYear."' selected>".$StartYear."</option>"; else echo "<option value='".$StartYear."'>".$StartYear."</option>"; } echo "</select></td><td align='center' width='60'><select name='StartMonth'>"; for ($StartMonth = 01; $StartMonth <= 12; $StartMonth++) { if ($StartMonth == date("m") && $choice == 0) echo "<option value='".$StartMonth."' selected>".$StartMonth."</option>"; elseif ($StartMonth == $_POST['StartMonth'] && $choice == 1) echo "<option value='".$StartMonth."' selected>".$StartMonth."</option>"; else echo "<option value='".$StartMonth."'>".$StartMonth."</option>"; } echo "</select></td><td align='center' width='60'><select name='StartDay'>"; for ($StartDay = 01; $StartDay <= 31; $StartDay++) if ($StartDay == $_POST['StartDay'] && $choice == 1) echo "<option value='".$StartDay."' selected>".$StartDay."</option>"; else echo "<option value='".$StartDay."'>".$StartDay."</option>"; echo "<td width='60' align='center'><strong>To</strong></td>"; echo "<td align='center' width='60'><select name='EndYear'>"; for ($EndYear = 2005; $EndYear < 2008; $EndYear++) { echo $EndYear; if ($EndYear == date("Y") && $choice == 0) echo "<option value='".$EndYear."' selected>".$EndYear."</option>"; elseif ($EndYear == $_POST['EndYear'] && $choice == 1) echo "<option value='".$EndYear."' selected>".$EndYear."</option>"; else echo "<option value='".$EndYear."'>".$EndYear."</option>"; } echo "</select></td><td align='center' width='60'><select name='EndMonth'>"; for ($EndMonth = 01; $EndMonth <= 12; $EndMonth++) { if ($EndMonth == date("m") && $choice == 0) echo "<option value='".$EndMonth."' selected>".$EndMonth."</option>"; elseif ($EndMonth == $_POST['EndMonth'] && $choice == 1) echo "<option value='".$EndMonth."' selected>".$EndMonth."</option>"; else echo "<option value='".$EndMonth."'>".$EndMonth."</option>"; } echo "</select></td><td align='center' width='60'><select name='EndDay'>"; for ($EndDay = 01; $EndDay <= 31; $EndDay++) { if (($EndDay == date("d")) && ($choice == 0)) echo "<option value='".$EndDay."' selected>".$EndDay."</option>"; if ($EndDay == $_POST['EndDay'] && $choice == 1) echo "<option value='".$EndDay."' selected>".$EndDay."</option>"; else echo "<option value='".$EndDay."'>".$EndDay."</option>"; } // this is the submit button to apply the date range filter echo "</td><td colspan='8' align='center'><input type='submit' name='Query' value='Apply Filter'></td>"; echo "</tr></table>";} // end of DisplayDateTable() function FormatDate($Year, $Month, $Day, $choice){ // this function takes in the start date and end range selection from the user and format it to be read by MySQL. // these are some tricky problem when the we use the timestamp to filter out the results. We need to add // the trailing zero for any month and day selection less than 10. $Date = $Year; if ($Month < 10) $Date = join (array ($Date, "0")); $Date = join (array ($Date, $Month)); if ($Day < 10) $Date = join (array($Date, "0")); if ($choice == 0) // start date $Date = join (array ($Date, $Day, "000000")); else // end date $Date = join (array ($Date, $Day, "235959")); return $Date;} // end of StartDate()---------------------------------------------------------------------------------- Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 17, 2006 Share Posted March 17, 2006 For the user to enter the time of choice could use select boxsFor hour 1 - 24 For min 1 - 60repeat the same for min from 1 - 60min[code]<SELECT NAME="hour"><OPTION VALUE="1">1pm</OPTION><OPTION VALUE="2">2pm</OPTION><OPTION VALUE="3">3pm</OPTION><OPTION VALUE="4">4pm</OPTION><OPTION VALUE="5">5pm</OPTION><OPTION VALUE="6">6pm</OPTION><OPTION VALUE="7">7pm</OPTION><OPTION VALUE="8">8pm</OPTION><OPTION VALUE="9">9pm</OPTION><OPTION VALUE="10">10pm</OPTION><OPTION VALUE="11">11pm</OPTION><OPTION VALUE="12">12pm</OPTION><OPTION VALUE="13">1am</OPTION><OPTION VALUE="14">2am</OPTION><OPTION VALUE="15">3am</OPTION><OPTION VALUE="16">4am</OPTION><OPTION VALUE="17">5am</OPTION><OPTION VALUE="18"6am</OPTION><OPTION VALUE="19">7am</OPTION><OPTION VALUE="20">8am</OPTION><OPTION VALUE="21">9am</OPTION><OPTION VALUE="22">10am</OPTION><OPTION VALUE="23">11am</OPTION><OPTION VALUE="24">12am</OPTION></SELECT>[/code]Hope this helps. Quote Link to comment Share on other sites More sharing options...
nadalia Posted March 17, 2006 Author Share Posted March 17, 2006 thanks, redarrow. A list of option is one way to go. At this point, what I am concerned the most is how to format the time to be ready by mysql?Anybody can help, give me a clue? Thanks a million in advance!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.