Sunday, 1 September 2013

What is the proper algorithm to trace time conflict in php/mysql?

What is the proper algorithm to trace time conflict in php/mysql?

I'm working with a time scheduling project where I can schedule materials
by time and I am really really confused on how can I trace the time
conflict within a time range. I worked with many(I think) algorithms but
still no luck. My brain is saturated that's why I ask anyone here who can
help me.

So I have these data in my database:
------DB Table schedule_dummy --------
material | date | start_time | end_time
----------------------------------------------------------
7 | 2013-08-01 | 13:00:00 | 14:00:00
8 | 2013-08-01 | 13:30:00 | 14:00:00
10 | 2013-09-01 | 13:30:00 | 15:00:00
----------------------------------------------------------
I used this data to check the availability of a certain material in a
particular time. And so if the value of start_time andend_time is equal to
or in between those time in the database the material will not be
available. I tried so many query but doesn't work with many cases.
Here are some queries that i've tried so far.
$sql = "SELECT materialID
FROM schedule_dummy WHERE (date_reserve = ?)
AND (? BETWEEN start_time AND end_time
OR ? BETWEEN start_time AND end_time)";
And
//I've tried this query but in some cases doesn't work dunno if I'm
missing something.
$sql = "SELECT * FROM schedule_dummy
WHERE date_reserve = ?
AND start_time >=? AND start_time <=?";
So could anyone who knows some algorithm to trace the time conflict? So
that I can retrieve those available materials in my database? Thanks!

No comments:

Post a Comment