PDA

View Full Version : Code Troubleshooting



es3
24 Jul 2006, 04:29 PM
OK, so here is the deal. I've been working on this the past few days, and it doesn't seem to want to work, and I can't figure it out. It's a bit messy, and I apologize for that, but I'm stumped.

I'm trying to get the date calculation function to run after the lists create, but it doesn't seem to want to work, and I can't really figure out why. I've also noticed that the commands below the functions such as :
"echo '<p>Today is ' . date ('l') . '. The current time is ' . date ('g:i a') . '.</p>';"
don't end up executing, and I was hoping someone could shed some light on this for me. Can't really figure out why this isn't working. By the way, this script is designed to see which date is greater than another date. Thanks!


"<h1 id="mainhead">Select a Date:</h1>
<form action="test3.php" method="post">

<?php

function which_date_is_greater($dateA, $dateB) {

if (is_numeric($dateA['year'])) { // Check if $dateA[year] is numeric
$functionYear_A = $dateA['year'];
} else {
$errors[] = 'Year \'A\' is not numeric.';
} // End $dateA Year numeric IF

if (is_numeric($dateA['mon'])) { // Check if $dateA[mon] is numeric
$functionMonth_A = $dateA['mon'];
} else {
$errors[] = 'Month \'A\' is not numeric.';
} // End $dateA Month numeric IF

if (is_numeric($dateA['mday'])) { // Check if $dateA[mday] is numeric
$functionDay_A = $dateA['mday'];
} else {
$errors[] = 'Day \'A\' is not numeric.';
} // End $dateA Day numeric IF

if (is_numeric($dateB['year'])) { // Check if $dateB[year] is numeric
$functionYear_B = $dateB['year'];
} else {
$errors[] = 'Year \'B\' is not numeric.';
} // End $dateB Year numeric IF

if (is_numeric($dateB['mon'])) { // Check if $dateB[mon] is numeric
$functionMonth_B = $dateB['mon'];
} else {
$errors[] = 'Month \'B\' is not numeric.';
} // End $dateB Month numeric IF

if (is_numeric($dateB['mday'])) { // Check if $dateB[mday] is numeric
$functionDay_B = $dateB['mday'];
} else {
$errors[] = 'Day \'B\' is not numeric.';
} // End $dateB Day numeric IF


if (!empty($errors)) { // Check if there were any errors
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
} else { //if there are no errors, then continue


if ($functionYear_A > $functionYear_B) { // Compare years
echo 'Date \'A\' is greater than Date \'B\'';
//return 0;
} elseif ($functionYear_A < $functionYear_B) {
echo 'Date \'A\' is less than Date \'B\'';
//return 0;
} else { //echo 'must be equall, next stage<br>';




if ($functionMonth_A > $functionMonth_B) { // Compare months
echo 'Date \'A\' is greater than Date \'B\'';
//return 0;
} elseif ($functionMonth_A < $functionMonth_B) {
echo 'Date \'A\' is less than Date \'B\'';
//return 0;
} else { //echo 'must be equall, next stage<br>';




if ($functionDay_A > $functionDay_B) { // Compare days
echo 'Date \'A\' is greater than Date \'B\'';
//return 0;
} elseif ($functionDay_A < $functionDay_B) {
echo 'Date \'A\' is less than Date \'B\'';
//return 0;
} else { echo 'Dates are equall';

} // End Compare Days Else
} // End Compare Months Else
} // End Compare Years Else
} // End Error Else
} // End of the function definition.


// This function makes three pull-down menus for the months, days, and years.
function make_calendar_pulldowns($m1, $d1, $y1, $m2, $d2, $y2) {

// Make the months array.
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

// Make the months pull-down menu.
echo '<br>Date A:<br>';
echo '<select name="monthA">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\"";
if ($key == $m1) { // Preselect.
echo ' selected="selected"';
}
echo ">$value</option>\n";
}
echo '</select>';

// Make the days pull-down menu.
echo '<select name="dayA">';
for ($day = 1; $day <= 31; $day++) {
echo "<option value=\"$day\"";
if ($day == $d1) { // Preselect.
echo ' selected="selected"';
}
echo ">$day</option>\n";
}
echo '</select>';



// Make the years pull-down menu.
echo '<select name="yearA">';
for ($year = 2005; $year <= 2015; $year++) {
echo "<option value=\"$year\"";
if ($year == $y1) { // Preselect.
echo ' selected="selected"';
}
echo ">$year</option>\n";
}
echo '</select>';

//new line
echo '<br><br>Date B:<br>';

// Make the months pull-down menu.
echo '<select name="monthB">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\"";
if ($key == $m2) { // Preselect.
echo ' selected="selected"';
}
echo ">$value</option>\n";
}
echo '</select>';

// Make the days pull-down menu.
echo '<select name="dayB">';
for ($day = 1; $day <= 31; $day++) {
echo "<option value=\"$day\"";
if ($day == $d2) { // Preselect.
echo ' selected="selected"';
}
echo ">$day</option>\n";
}
echo '</select>';

// Make the years pull-down menu.
echo '<select name="yearB">';
for ($year = 2005; $year <= 2015; $year++) {
echo "<option value=\"$year\"";
if ($year == $y2) { // Preselect.
echo ' selected="selected"';
}
echo ">$year</option>\n";
}

} // End of the function definition.


global $errors;
$errors = array();


if (isset($_POST['submitted'])) {

$dateA = array();
$dateB = array();

//$dateA = getdate();
$dateA['year'] = $_POST['yearA'];
$dateA['mon'] = $_POST['monthA'];
$dateA['mday'] = $_POST['dayA'];

$dateB['year'] = $_POST['yearB'];
$dateB['mon'] = $_POST['monthB'];
$dateB['mday'] = $_POST['dayB'];

which_date_is_greater($dateA, $dateB);

make_calendar_pulldowns ($dateA['month'], $dateA['day'], $dateA['year'], $dateB['month'], $dateB['day'], $dateB['year']);

//which_date_is_greater($dateA, $dateB);

// Print the current day and time.
echo '<p>Today is ' . date ('l') . '. The current time is ' . date ('g:i a') . '.</p>';

echo 'year A = ' . $dateA['year'] . '<br>month A = ' . $dateA['mon'] . '<br>day A = ' . $dateA['mday'] . 'year B = ' . $dateB['year'] . '<br>month B = ' . $dateB['mon'] . '<br>day B = ' . $dateB['mday'];

} else {

// Get today's information and call the function.
$dates = getdate();
make_calendar_pulldowns ($dates['mon'], $dates['mday'], $dates['year'], $dates['mon'], $dates['mday'], $dates['year']);

echo '</form><p><br /></p>'; // End of form.

// Print the current day and time.
echo '<p>Today is ' . date ('l') . '. The current time is ' . date ('g:i a') . '.</p>';

} // End else


// End PHP
?>

<p><input type="submit" name="submit" value="Compare Dates" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>

"

I'm also trying to get the last date selected, that was sent to the server, to pop back up as the selected date as the script executes again, however I am fairly sure I know why this is not working, and have not got around to messing with it yet. (This works with the years, as it is numerical)