Jump to content

Find next session between two dates/times


George Botley

Recommended Posts

Hello,

 

I am struggling here. Basically I have integrated a Google Maps API with a website to show the location of the next session.

 

This script will take the next session and return its location, so the lat and long can be fetched from another table and fed into the API.

 

Here is the timetable in a MySQL table:

 

screenshot20111108at224.png

 

I am trying to do/say the following:

 

* Show current session (if in progress)

* Show next session. (Only to be fetched from db when the previous session has expired)

* If there are no sessions left on today's date, show next session on next day with sessions.

 

How could I write this as a PHP query in order to the fetch the location data?

 

Thanks,

George.

 

Link to comment
Share on other sites

I think you are making it more difficult than it needs to be. This should get you what you need.

SELECT *
FROM table
WHERE end_time >= NOW()
ORDER BY end_time
LIMIT 1

 

If there is a current session, the end time would be past NOW(), otherwise it will get you the very next session. The only problem you would have is if sessions overlap and the session length can be different.

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.