Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:52:36+00:00 2026-05-31T09:52:36+00:00

ok so I am trying to select rows from DB to see if there

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:52:37+00:00Added an answer on May 31, 2026 at 9:52 am

    It appears that you are looking to see whether a new entry overlaps at all with any existing entry. The new entry is specified by a start time (1331386200 in your example), and a duration (1800, inferred from commentary and 1331386200 + 1800 = 1331388000).

    There are a number of questions on SO (including Determining whether two date ranges overlap) that deal with overlapping time periods, but the basic technique for determining whether two periods, denoted by [s1, e1] and [e2, s2] overlap is simple:

    if (s1 < e2 && s2 < e1)
        ...the intervals overlap...
    

    You can juggle with < vs <= if you need to. You can add extra criteria to your query as needed, of course.

    Applying that to your example, it appears that you should be writing something like this:

    -- s1 == calTime
    -- e1 == calTime + duration
    -- s2 == 1331386200
    -- e2 == 1331388000
    
    SELECT *
     FROM calendar_01
    WHERE calTime    < 1331388000            -- s1 < e2
      AND 1331386200 < (calTime + duration)  -- s2 < e1
      AND agentID = 1                        -- other criteria
    ORDER BY calTime ASC
    LIMIT 0 , 30
    

    If that returns any data, then there is a conflict between the new data and one or more existing rows of data (the statement will return a list of up to the first 30 such rows).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, I was trying to select rows from one table if there are no
I am trying to select rows from a table where one of the (NVARCHAR)
In trying to select elements that have any attributes, the following throws a jQuery
I'm trying to select data from a table defined similar to the following :
I'm trying to select a random 10% sampling from a small table. I thought
I'm trying to select a column from a single table (no joins) and I
I am trying to list out all records from a database that have not
Have seen multiple posts on this but I can't see any which answer my
I'm trying to use the SUM function to count rows from 3 tables, which
I see from reading other posts on this site, there a similar solutions to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.