Forum Moderators: coopster
I'm working on a project for a resort.
The room rates for this resort are the same all year around except for a certain holiday period when the rates jump.
I'm referencing a DB table with the fields "startHigh" and "endHigh". startHigh contains a text string of "March 24". endHigh contains "April 7".
If someone makes a reservation between these two dates, they get the high-season rate; conversely, if someone makes a reservation before or after this period, they get the regular "off-season" rates.
So, I want to write a function to detect if the persons check-in date falls between the startHigh and endHigh parameters, like:
if ($checkIn >= $startHigh && $checkIn <= $endHigh) {
$rate = $highRate;
} else {
$rate = $lowRate;
}
Is this the correct way to determine if one variable falls between a range of two other variables? What I'm very uncertain about is if text strings can be compared this way, as $checkIn is fed by a month and day select list (so it's a text string) and, as mentioned, my db fields are of type varchar.
Any and all assistance grealy appreciated,
Neophyte
Also think of it this way... The next change request that's going to come to you is "Can we also make rates higher for the weekend of #*$!x?"
You'll have to convert the user's input into a date string compatible with mySQL, but you were parsing and validating the input anyway, to make sure the user didn't slip anything behind you, right?
At the very least you could have a table called rate that has the start and end dates, along with the rate. Then do something like
SELECT rate,
end -
start AS length
FROM rate
WHERE START < "2006-01-04"
AND END > "2006-01-04"
ORDER BY length
LIMIT 1
to get the rate. This doesn't handle the corner cases like if a stay extends over two different periods, but I don't think yours did either.
Sean