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

  • Home
  • SEARCH
  • 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 7970069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:20:25+00:00 2026-06-04T07:20:25+00:00

I am trying to make a simple reservation system. I have a table called

  • 0

I am trying to make a simple reservation system. I have a table called reservation that holds reservation time, and id of the customer who reserved it (see below for schema). And I have another table room, this table is for room types, so each type of room has an entry in this table for it’s size and price. And another table rooms, for actual entry about each room. In the query I try to make, I want to select one room, that is of particular type, and that is available in the given time slice. Something like this;

Select number from rooms where type = 4 and available between $start-date and $end-date;

I couldn’t figure out how to write available between part of the query. Relevant part of my schema follows;

CREATE TABLE IF NOT EXISTS `reservation` (
  `rid` int(11) NOT NULL AUTO_INCREMENT, /* reservation id */
  `number` int(11) NOT NULL, /* number of the room for this reservation */
  `cid` int(11) NOT NULL, /* customer id */
  `begin` date NOT NULL,
  `end` date NOT NULL,
  PRIMARY KEY (`rid`),
);

CREATE TABLE IF NOT EXISTS `room` (
  `rid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `size` tinyint(3) unsigned NOT NULL,
  `price` float NOT NULL,
  PRIMARY KEY (`rid`)
);

CREATE TABLE IF NOT EXISTS `rooms` (
  `number` smallint(5) unsigned NOT NULL,
  `type` int(11) NOT NULL,
  `available` tinyint(1) NOT NULL,
  `cid` int(11) DEFAULT NULL,
  PRIMARY KEY (`number`),
);
  • 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-06-04T07:20:26+00:00Added an answer on June 4, 2026 at 7:20 am

    I am not sure if this is a good solution, but I ended up doing this:

    SELECT number, room.price
    FROM rooms
    JOIN room on room.rid = rooms.type 
    WHERE rooms.type = ".$room_id."
    AND rooms.number NOT IN (
        SELECT number FROM reservation
        WHERE end >= FROM_UNIXTIME(".$start.")
        AND begin <= FROM_UNIXTIME(".$end.")
    ) LIMIT 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a simple reservation system. I have two tables as
Trying to make simple minesweeper game in python, but have one problem. I have
Trying to make a simple client that consumes a web service using RemObjects SDK,
I'm trying to make simple many-to-one association, using NHibernate.. I have class Recruit with
I am trying to make simple regex that will check if a line is
I am trying to make a simple program to convert time given in seconds
Trying to make simple jQuery function to create a scrollToTop button that fades in
I am trying to make simple app that allows one to compare image to
I am trying to make a simple AJAX calling in PHP and have a
I'm trying to make simple animation that would repeat several times (or infinitely). It

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.