Jump to content

nadalia

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

nadalia's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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!!
  2. 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() ----------------------------------------------------------------------------------
×
×
  • 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.