ok so I am trying to select rows from DB to see if there are any clashes within the calendar and I have come across another issue
here is my code
$query3 = $dbh->prepare("SELECT * FROM calendar_" . $companyID . " WHERE (calTime+duration) > :calstart AND (calTime+duration) <= (:calend + (duration-(:calend-calTime))) AND agentID = :agentID ORDER BY calTime ASC");
$query3->bindParam(':calstart', $time);
$calend = $time + $duration;
$query3->bindParam(':calend', $calend);
which looks something a like this in more readable SQL
SELECT * FROM calendar_01 WHERE (calTime + duration) > 1331386200
AND (calTime + duration) <= ( 1331388000 + ( duration - ( 1331388000 - calTime ) ) )
AND agentID =1
ORDER BY calTime ASC
LIMIT 0 , 30
the lower boundary obviously works fine however with the upper boundary I have the problem where if the duration of an event is 7200 2hrs and someone tries to enter a new event that is say only 1800 in length and starts 1800 after the first it will allow it even though the event that has been entered is 7200 long and would in fact overrun the new event. Therefore I need the upper boundary to be dynamic in the sense that if :calend < (calTime + duration) then select row otherwise use :calend as the upper boundary.
I though I was almost right with what I was attempting however this part
( 1331388000 + ( duration - ( 1331388000 - calTime ) ) )
ends up minus minus on some occasions therefore the upper boundary is much to large and includes rows when they should not be