Afficher un message
Vieux 05/10/2007, 14h58   #10
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Find next available slot in Calendar

Rik Wasmus wrote:
> On Fri, 05 Oct 2007 06:58:22 +0200, subtenante
> <zzsubtenantezz@gmail.com> wrote:
>
>> On Tue, 02 Oct 2007 18:02:58 -0700, ½aßrain <mccbrad@gmail.com> wrote:
>>
>>> Hi Guys,
>>>
>>> I have a table of events with a start and finish datetime.
>>>
>>> I am trying to write a php function that will return the next earliest
>>> start time that an event will fit. Will this be something that I can
>>> do just in mysql?
>>>
>>> or something much more complex?
>>>
>>> anyone have any tips?

>>
>> SELECT * FROM mytable
>> WHERE start > NOW()
>> ORDER BY start
>> LIMIT 1

>
> That's for the next event indeed. I gathered the OP meant 'next empty
> slot'. In which case these 'slots' should either have a table or the OP
> should tell us more about them.


I tried something like this several years ago in DB2 for a conference
room reservation system. I wasn't overly successful. I did get it to
work with temporary tables and recursive SQL, but the whole thing was a
huge mess. Even as a SP it was complicated and tough to understand.

I finally just did a simple query to fetch allocated timeslots, ordered
by the time, and had a C function find the first available slot. The
code came out much cleaner and more understandable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
 
Page generated in 0,04983 seconds with 9 queries