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 6901387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:40:02+00:00 2026-05-27T07:40:02+00:00

I’m creating a room suggestion feature for a room reservation system and I’m trying

  • 0

I’m creating a room suggestion feature for a room reservation system and I’m trying to figure out how to attack this query. So far I’ve got it excluding what rooms are reserved and in conflict with the desired room. Here is my query:

"SELECT * FROM room 
 WHERE roomcode NOT IN 
      (SELECT room FROM event 
       INNER JOIN room ON event.room = room.roomcode 
       WHERE ( 
                 (begintime <= $start AND endtime >= end) 
              OR (begintime >= $start AND endtime <= $end)
              OR (begintime <= $start AND endtime <= $end AND endtime >= $start) 
              OR (begintime >= $start AND endtime >= $end AND begintime <= $end) 
             ) 
             AND room = '$room' 
             OR room IN ($rooms) 
       ) 
       AND capacity >= $capacity AND min_capacity <= $capacity";

I’m sorry if that’s a mess.

The information I’m unable to get to right now is a list of rooms that become inactive when a particular room is reserved. For example, a room (n103abc) has three partitions. The whole room can be reserved as one, causing the three parts and their other combinations (n103a, n103b, n103c, n103ab, n103bc) to become inactive. Each room has a column in the database with the rooms it sets inactive formatted as a list separated only by a comma, no spaces.

Basically what’s going on is I’m trying to select rooms that don’t fall in any of the begintime/endtime conditions, aren’t the room reserved in those that fall into the begintime/endtime conditions, and aren’t inactive.

Any suggestions? I know that was a pain in the butt, but I hope someone can show me the light here. I’ve been staring at this for the last 5 hours with no progress. Thanks.

  • 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-27T07:40:03+00:00Added an answer on May 27, 2026 at 7:40 am

    The sentence…

    “Each room has a column in the database with the rooms it sets inactive formatted as a list separated only by a comma, no spaces.”

    …means your table is not even in the first normal form.

    So, you’d probably want to model this hierarchy in a more relational way – for example by introducing a room.parent_roomcode field that is a FOREIGN KEY toward the room.roomcode. If the parent_roomcode is NULL, this is the “parent” and if it’s non-NULL then this is the “child” (i.e. becomes inactive when parent becomes reserved). Let’s also assume this hierarchy is single-level only (i.e. there are no “grandchildren”).

    You could then query (roughly) like this:

    SELECT *
    FROM room
    WHERE
        NOT EXISTS (
            SELECT *
            FROM events
            WHERE
                NOT ($end <= begintime OR endtime <= $start)
                AND (
                    events.room = room.roomcode
                    OR events.room = room.parent_roomcode
                )
        )
        AND min_capacity <= $capacity
        AND $capacity <= capacity
    

    In plain English, select rooms such that:

    • There is no event such that:
      • It intersects with given time interval,
      • and is associated with the room or its parent.
    • And the capacity is appropriate.

    Details:

    • $end <= begintime OR endtime <= $start means the event is completely before or completely after the given interval (this works under assumption that $start <= $end and begintime <= endtime). Applying NOT gives an event that is either partially or completely in the interval.
    • events.room = room.parent_roomcode gives events that are connected to parent, meaning the child room is inactive. Since we are dealing with a single-level hierarchy, there is no need for a recursive query.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.