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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:53:17+00:00 2026-06-12T13:53:17+00:00

I’m writing a PHP/MySQL application for tracking appointments and I’m stuck on locating the

  • 0

I’m writing a PHP/MySQL application for tracking appointments and I’m stuck on locating the next available appointment based on whether any number of conditions are selected.

CREATE TABLE IF NOT EXISTS `appointments` (
`appointmentID` int(9) unsigned NOT NULL AUTO_INCREMENT,
`patientID` int(9) unsigned NOT NULL,
`apptTitle` varchar(50) NOT NULL,
`apptDate` date NOT NULL,
`apptTime` time NOT NULL,
`apptLength` int(4) NOT NULL,
`apptStatus` varchar(25) NOT NULL,
`physician` int(9) unsigned NOT NULL,
`apptType` varchar(30) NOT NULL,
`apptInvoice` varchar(10) NOT NULL,
`apptNotes` varchar(1000) NOT NULL,
`apptLocation` varchar(25) NOT NULL,
`apptReminder` int(4) NOT NULL,
 PRIMARY KEY (`appointmentID`),
 KEY `patientID` (`patientID`),
 KEY `physician` (`physician`),
 KEY `apptStatus` (`apptStatus`),
 KEY `apptLocation` (`apptLocation`),
 KEY `apptType` (`apptType`)
 ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

Side note: You’ll notice my Type, Location, Status fields are varchar’s, and they’re linked to lookup tables. So, I’m storing the actual value, not an ID for each item (so each lookup table is just the field value as the PK, no ID column). I’ve done this to reduce joins in the future, but I know this is slightly denormalized. If this is the wrong way to go, feel free to let me know, I just hadn’t found overwhelming evidence one way or the other besides knowing I wouldn’t have to do those joins later if I denormalized a bit. There is “on update” logic in place so if a change is made it will update the values in the appointments table.

The goal here is to show all available appointment slots (these are 15-minute slots, so 12:00am-12:14:59am, 12:15:00am-12:29:59am, etc.). By default, I’d just show all appointment slots for the next X days (probably 14) with no restrictions. But, if a patient wants to see a particular doctor, I’d want to limit to that, or if a doctor only needs a consultation, I can limit the location to a consultation room and not take up an exam room. Or, we know a follow-up needs to be scheduled for X months, so I can start showing days after that time has elapsed. Or, patient can only make appointments on weekends or after 5pm.

From what I’ve read, I need some sort of appointment “slots” table, but I’m not sure how I would structure that table so I could compare it against the existing appointments and find my slots.

I know a decent bit about MySQL and I’m always up for a challenge, but I can’t seem to wrap my head around how I would do this. I’ve looked for similar questions, but none really seemed to cover the amount of customization I’m looking for and I couldn’t figure out how to tweak that code to make it work for me. Hopefully, someone can help me understand where I need to go with this idea!

Thank you in advance for your help!

  • 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-12T13:53:18+00:00Added an answer on June 12, 2026 at 1:53 pm

    I don’t think planning for future “reduction of joins” is a good reason. You should be more worried about the future headache you’re creating (for you or someone else) with the “update logic”. Like you said, fields such as type, location, and status could have metadata relevant to your slots query (type “requires followup in X months”, location “is exam room”), so you’re going to need to join eventually anyway. Even just to find available locations for a time slot, you’ll definitely need to join, if I understand correctly.

    I’m guessing a “slot” is like a 5 minute timespan? Eg. 12:00-12:04:59, 12:05-12:09:59, etc?

    Like Alex said above, you’ll need an “all possible slots” table to left join against (temporary or not).

    I’d probably create it permanently on disk, since it’s referenced a lot. It sounds like a waste, but the other option is to generate it dynamically each time, which isn’t great either.

    Then to say find a doctors available slots, something like:

    SELECT a.* 
    FROM slots AS a
    LEFT JOIN appointments AS b
    ON a.startDate BETWEEN b.apptDate AND DATE_ADD(b.apptDate,INTERVAL b.apptTime MINUTE)
    AND b.physician=1234 
    WHERE b.appointment IS NULL
    

    I can try to help with your other more complicated queries if this sounds like it’s on the right track of what you’re after.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I am writing an app with both english and french support. The app requests
I'm trying to create an if statement in PHP that prevents a single post

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.