Jump to content

Filtering Dumped Data Based On Row+N Conditions


RamoneDaBone

Recommended Posts

I am creating a scheduling script in PHP from a mySQL database. My problem can be explained with the following example. I have 10 appointment cells in day x (0-9). Each appointment cell has an adjacent corresponding cell to describe whether the appointment is available or not (either 0 or 1...and call this NID). I will need to identify whether appointment t, t+1, t+2 and t+3 are all available. In other words, some appointments will require multiple time slots. How can I filter through the dumped sql data with PHP by looking at the NID and checking whether t, t+1, t+2, t+3 are available? I've tried enumerating the time slots and putting them in arrays but can't figure this one out.

 

Thanks for any ideas biggrin.gifbiggrin.gifbiggrin.gifohmy.gifohmy.gifohmy.gif

Link to comment
Share on other sites

Lets say the table has 2 columns

 

column 1 has a date and tid. for example.... june 1 9:00 am would be 4232, june 1 9:30am would be 4233, june 1 10:00am would be 4234

column 2 has a boolean, either 0 or 1. 0 indicates the time slot is available while 1 indicates that its not.

 

through another language interacting with PHP i will send requests for appointments of different lengths. for example...i will need to book a 1.5 hour appointment on june 1 starting at 9:00am. so i will need to check whether 930 and 10 am are also available.

 

do you need more info?

 

thanks :)

Edited by RamoneDaBone
Link to comment
Share on other sites

Can you just post the actual table structure with some data?

 

Edit: I take that back, rather than storing whether or not a "slot" is open, you should only store the reserved datetimes. Then if it doesn't exist, it's available.

Edited by Jessica
Link to comment
Share on other sites

Maybe I should make it more clear.

 

September 22nd 2012 9:00am is 1

September 22nd 2012 9:30am is 2

September 22nd 2012 10:00am is 3

...

 

September 22nd 2012 4:30pm is 15

September 22nd 2012 5:00pm is 16.

 

 

Then September 23rd 2012 9:00am is 17

September 23rd 2012 9:30am is 18

September 23rd 2012 10:00am is 19.

 

Does that make sense? I was trying to reduce the number of parameters. I can create a simple formula that will translate todays date and time into an ID number (....like 18 for September 23rd 2012 at 9:30am) that will always hold true regardless of the time or date that I submit the request.

 

Do you see how my issue lies in checking the row+n's depending on what type of appoointment it is?

Link to comment
Share on other sites

Not really, I get what he's saying.

09-22-2012 9am = 1, 9am to 5pm is 12 spots, I'm going to throw in an hour for a lunch break so 10 spots.

take the current date and get the number of days between 9-22-2012 and now, multiply by 10, and add 1 for every half hour.

 

it's a bad bad idea, but not a hard formula.

Edited by Jessica
Link to comment
Share on other sites

ST ET

| |

-----------+-------------------+---------

| | ---

s1--------------e1 | |

| s2-----------e2 | Booking required from ST to ET

| | |

s3--------------------------e3 |-- If any of these booking exist

| | | the time slot is not available

| s4------e4 | |

| | | ie s < ET AND e > ST

| | ---

 

Why the f*** can't it preserve spaces?

 

 

Store your booking start and end time times as DATETIME type fields.

 

If someone wants a booking from 2012-09-24 09:00:00 to 2012-09-24 10:30:00 then you can find if any of the conditions, in attached image, exist with this query

 

SELECT COUNT(*) FROM bookings

WHERE starttime < '2012-09-24 10:30:00' AND endtime >'2012-09-24 09:00:00'

 

If the count is zero, the slots are free

post-3105-0-25755500-1348357964_thumb.png

Edited by Barand
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.