Jump to content

calendar time slots and key using php sqlwW


tom7890

Recommended Posts

Hey 

 

I was hoping i could get some help in regards to a time slot calendar i am working on. I have created a calendar in php, a table for the time slots but i am a little stuck on how to do the next tasks. 

 

I need a key for the calendar so which shows what days are: 

 

 1. Available to be book 

 2. Partially booked

 3. Fully booked

 4. Closed

 

I need to create a table in sql for the key and then where days are closed i need to color them say red, those that are available color green etc.. 

 

Im stuck on the how to implment this in sql.

 

 How do i link it all up to the database

Link to comment
Share on other sites

The key to this whole process is having sufficient data stored on each "day" so that you can write a query that determines the things you wish to find out about that specific "day". So - have you that data? You say you are trying to manage "time slots", therefore I assume that you table contains records that identify each time slot for use. Is every possible time slot created in the table before it is allotted, or do you only create a record when someone books it? That would be one way to identify availability.

 

Once a slot is booked do you treat that specific time slot as 'fully booked' and therefore unavailable to anyone else? Again - that answers the availability question.

 

With my two examples (very small help) I'm hoping that you are inspired to think about your problem in a more logical way and come up with more ideas on solving your needs.

Link to comment
Share on other sites

The user will select a day from a calendar, a form will show with timeslots, once they pick a time another form will appear where they enter details and book that timeslot. 

 

I am trying to make a key for the calendar which shows what is available and what is not, but i cant seem to get it around my head on how to do this. 

 

I am not asking for code or anything, im trying to see if anyone can explain in such a way that i can implement like tasks of what need to done, i.e. 

 

1) Create a key table 

 

etc

Edited by tom7890
Link to comment
Share on other sites

I tried to point you in the right direction. The thought of creating a 'key' is not going to work for you I don't believe. Think of querying for concepts in your data, not 'keys'. Define how the data has to look for a given situation and use that as your 'key' if you will.

 

Closed - when a time slot is assigned

Open - when a time slot is undefined or assignment field is empty

 

As for partial and full usage - is this really something that will occur? Can you possibly get "full utilization" of time slots when you book them back to back for different users? Have you thoug about how the actual use of your resource will happen? Think about a meeting room. Someone books it for one hour. Yet you have to have it available for a certain amount of time prior to that hour for it to fill up, and for some time afterwards for it to empty and for it to be re-fitted for the next user (cleaning?). So - you have to actually book a time slot for extra time. Do you really want to be booking partial time slots?

Link to comment
Share on other sites

The code I gave you in your original thread on this topic (you now have 3 of them) showed you how to colour code your cells and almost all the other things you said you wanted (like showing available times on hovering, making the cells clickable, displaying a booking form for the clicked day).

 

Look at the code, the answers are there.

Link to comment
Share on other sites

I set up styles with 3 background colours

  • pale green - default, no bookings
  • yellow - partially booked days
  • red - fully booked days
td {
    background-color: #C4E5C4;
}
td.full {
    background-color: red;
    color: white;
    font-weight: 600;
}
td.partial {
    background-color: yellow;
    color: black;
    font-weight: 600;
}

This the relevant code to apply those classes

        if (isset($bookings[$d->format('Y-m-d')])) {            // are there bookings in db for that day?
            $tit[$dow] = wordwrap($bookings[$d->format('Y-m-d')][1],34);  // construct popup of free times (on hover)
            if ($bookings[$d->format('Y-m-d')][1])              // are there free slots?
                $clsArray[$dow] = "class='day partial $now'";   // if so, apply "partial" class
            else
                $clsArray[$dow] = "class='day full $now'";      // if not, apply "full" class
        }

Link to comment
Share on other sites

Yeah, the style definitions go in the stylesheet. The code he is showing you is how to apply the correct style class to your calendar's day elements depending on the conditions if there are slots available, or not.

Edited by CroNiX
Link to comment
Share on other sites

You're still using a style sheet with Barand's suggestion. The only thing the code he presented is doing is creating a dynamic class name depending on the day's schedule. Parse the code and read the helpful comments - if there's a booking on that day, the code checks to see if there are free time slots. If so, it applies the 'partial' class tag, because the day is partially booked. If there are no free time slots on that day, it applies the 'full' class tag, because the day is fully booked. In your style sheet, create the .day{}, .partial{}, and .full{} class style definitions and you should be good to go. There's not a lot to understand with this part of it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.