George Botley Posted November 8, 2011 Share Posted November 8, 2011 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: 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. Quote Link to comment https://forums.phpfreaks.com/topic/250737-find-next-session-between-two-datestimes/ Share on other sites More sharing options...
Psycho Posted November 8, 2011 Share Posted November 8, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/250737-find-next-session-between-two-datestimes/#findComment-1286429 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.