soryy - my mistake will come back.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
I don't quite understand what you're trying to achieve. Is it split the string into parts, to get the day? IF so, you have a number of ways, SOME of which follow:
$str = "9:30PM -10:30PM TTH";
$r = preg_split('/ /',$str);
$day1 = $r[count($r)-1];
echo "PREG DAY: $day1 ";
$pos = strrpos($str, " ");
if ($pos !== false) {
echo "STRRPOS/SUBSTR DAY: " . substr($str,$pos) . "";
}
$r = explode(" ",$str);
$day3 = $r[count($r)-1];
echo "EXPLODE DAY: $day3 ";
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
OK, I have some code (24-ish lines) that solves your problem if all formats are consistent. You have provided 2 different formats in your posts. Where is the data held in a db?
is the format:
8:00AM -9:30AM TTH
or
8:00am-9:30am | TTH
or
9:00am-10:30am | THURSDAY
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
You'd be better off storing data as:
sub | start_time | end_time | day
=================================
a | 900 | 1030 | 4
b | 1200 | 1345 | 5
The days relate to the common format 0 = Sun ... 6 = Sat
Times are set in integers (4 digit max: 0 - 2359)
You can now use simple arithmetic comparisons (<, >, >=, <=) to check collisions.
To check if a new period collides with any existing periods, try this logic for a loop:
IF
(newClassStartTime >= storedStartTime AND newClassStartTime < storedEndTime)
OR
(newClassEndTime > storedStartTime AND newClassEndTime <= storedEndTime)
OR
(newClassStartTime <= storedStartTime AND newClassEndTime >= storedEndTime)
THEN
PRINT "It's a clash!"
Note the above is in pseudo-code (not some freaky SQL)
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
In what format is the TIME_ROW_START and the TIME_ROW_END ? ANd the $timestart and $timeend
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
"SELECT * FROM table_name
WHERE TIME_ROW_START >= '$timestart' AND TIME_ROW_END =< '$timeend'";
That example will check whether the new times ($timestart and $timeend) are found AT or WITHIN any stored periods. For further collisions you'll need to check whether $timestart is WITHIN TIME_ROW_START and TIME_ROW_END and $timeend is WITHIN TIME_ROW_START and TIME_ROW_END.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Tried it? I don't quite follow the logic. Where did LABTIME come from??
Can you post your MySQL table structure and datatypes? Also describe what the time-related fields are for. Then perhaps we'll be able to make sense of what you're trying to do.
I assume that you're getting a start and end time from a form and then want to check that this new 'period' doesn't collide with exisitng DB-stored 'periods'.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080