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

The Archive Base Latest Questions

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

PHP/MySQL SELECT I have a table with available hours a specific day for a

  • 0

PHP/MySQL SELECT

I have a table with available hours a specific day for a meeting room. The Temp_Res get the timestamp when a booking is ongoing (to lock those rows). I would like to get every possible time slot if meeting to be booked is 2 hours.

Day     Hour      Temp_Res
22        8           0000-00-00 00:00:00
22        9           0000-00-00 00:00:00
22        10         0000-00-00 00:00:00
22        11         2012-05-18 22:02:00
22        12         2012-05-18 22:02:00
22        13         2012-05-18 22:02:00
22        14         0000-00-00 00:00:00
22        15         0000-00-00 00:00:00
22        16         0000-00-00 00:00:00
22        17         0000-00-00 00:00:00

So, if the time slotneeded is 2 hours, only Hour 8, 9, 14, 15, 16 would be the output. (I would then use the hour and add 2 to get the slots: 8-10, 9-11, 14-16, 15-17 and 16-18)
If time slot is 3 hours, only Hour 8, 14, 15 would be the output and slots: 8-11, 14-17, 15-18….etc
To be able to do this in a SELECT (if possible) there must be a way of looking on the other rows in the table to determine if the specific row shall be included or not.

1. Is it possible to look on other rows and do this with a SELECT with WHERE (or similar)?

2. If possible, could you please guide me into the right direction?

3. Other solutions/ideas (except the ones below) are also very appreciated!

Otherwise I have to solve it by:
a) creating an extra time slot table
b) having an extra column stating the maximum time slot for that specific row, see below.

Day     Hour   Slot      Temp_Res
22        8        3           0000-00-00 00:00:00
22        9        2           0000-00-00 00:00:00
22        10      1           0000-00-00 00:00:00
22        11      0           2012-05-18 22:02:00
22        12      0           2012-05-18 22:02:00
22        13      0           2012-05-18 22:02:00
22        14      4           0000-00-00 00:00:00
22        15      3           0000-00-00 00:00:00
22        16      2           0000-00-00 00:00:00
22        17      1           0000-00-00 00:00:00

SELECT Day, Hour FROM table
WHERE Slot>=2 AND Temp_Res<“2012-05-18 22:00:00”
GROUP BY Day, Hour

  • 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-04T05:44:21+00:00Added an answer on June 4, 2026 at 5:44 am

    I would suggest using the start time and the meeting length to compute the end time, which is equivalent to “the last hour that needs to be free in order for this booking to occur.” You can then use an inner join to only select start times where every hour up to the end time is also unbooked. For a four-hour meeting, your query might look like this:

    SELECT start.day, start.hour from table as start 
    INNER JOIN table as hour1
        ON ((hour1.hour = start.hour + 1) AND (hour1.TempRes = '0000-00-00 00:00:00'))
    INNER JOIN table as hour2
        ON ((hour2.hour = start.hour + 2) AND (hour2.TempRes = '0000-00-00 00:00:00'))
    INNER JOIN table as hour3
        ON ((hour2.hour = start.hour + 3) AND (hour3.TempRes = '0000-00-00 00:00:00'))
    WHERE table.TempRes = '0000-00-00 00:00:00'
    

    You can use a loop in PHP to add the required number of inner join clauses onto your query text (and because you’re using a variable you calculated yourself, you don’t have to worry about injection). It will always be (duration of meeting – 1).

    This will return no open times if someone tries to schedule a meeting that would go across midnight, but if that’s undesired you can easily write logic to increment the day variable appropriately.

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

Sidebar

Related Questions

I have a booking system in which I need to select any available room
Using PHP and MySQL, I want to select only 6 rows from table which
In my PHP application, I have a mysql table of articles which has the
I have a small PHP mysql query looking at a table in my database.
I have my php/mysql SELECT code which doesn't return a result to what I
I can't get my authors from my php quotes i have a quotes table:
I am trying to use PHP and MySQL's Create Table Select between two different
I have a table that get its rows from a MYSQL database <table id=table1>
So i have this script: <?php $query = mysql_query( SELECT meetup AS text, id
IS this bit of code in PHP/mysql considered a stored procedure? $sql = 'SELECT

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.