Skip to main content
July 26, 2006
Question

Structure/Array Help

  • July 26, 2006
  • 3 replies
  • 720 views


I need help formatting an array to store the following date ranges per room.

DATABASE Format
Room StartDate EndDate
------------------------------------------------------------------------------
Blue 10/23/2006 2/2/2007
Green 10/25/2006 10/26/2006
Yellow 11/2/2006 11/2/2006
Yellow 11/10/2006 11/13/2007

I am trying to use the following loop to get the ranges for each room, but how then do I apply that to an array for each record of each room and then append to the array.

<cfloop from="#GetDays.StartDate#" to="#GetDays.EndDate#" index="x">
<cfoutput>#dateformat(x, "MM/DD/YYYY")#</cfoutput><br>
</cfloop>

Thanks in advance for any help!!
This topic has been closed for replies.

3 replies

Inspiring
July 26, 2006
Start at sqare 1. You say you want to know what days each room is available.

What information do you have right now that tells you whether a room is available or already booked on any given day.
July 26, 2006
Hey Dan.

If you look at my first post you will see how the data are stored in the DB.

Room - StartDate - EndDate

Meaning this room is available starting on this date and ending this date. They are different for each room.
Inspiring
July 26, 2006
Ok, now I think I understand the question. You have selected the data from your db and it resembles what is in your original post. The objective is to fill in the missing dates.

<cfoutput quey = "q1">
<cfset thisdate = startdate>
#room#
<cfloop condition = "thisdate lte enddate>
  #thisdate#
<cfset thisdate = dateadd("d", 1, thisdate)>
</cfloop>
</cfoutput>
Inspiring
July 26, 2006
Look at the cfoutput tag in the cfml reference manual. If you don't have one, the internet does.

Pay particular attention to the group attribute and the example that shows the proper syntax for using it.
July 26, 2006


Dan, I'm familier with the group attribute for <cfquery>, how does this apply to my issue of getting the data I need from my query?
Inspiring
July 26, 2006
There needs to be a clearer understanding of what you are trying to
accomplish. Your loop does not make any sense to me, no matter which
way I try to twist my mind around it.

I presume that getDays is the name of the query, then your loop is
trying to say something like this.

<cfloop from="10/23/2006" to "2/2/2007" index="x">

Note that those are strings, not date objects, so this makes no sense.
It is basically equivalent to something like this.

<cfloop from="George" to "Robert" index="x">

So if you want to loop over the days between those two dates, you will
need to convert them to dates and use some kind of date loop. Something
I've done before:

<cfset loopDate = parseDate(getdays.startDate)>
<cfset endDate = parseDate(getdays.endDate)>

<cfloop condition="#dateCompare(loopDate,endDate,"d") GT 0#">
Do Stuff
<cfset LoopDate = dateAdd(LoopDate,"D",1)>
</cfloop>

Syntax not guaranteed, check documentation.

But all this would be based off only the first row of the query. If you
are trying to do something with each row, you will need a loop that
loops over the recordset.



DJ5MD wrote:
>
>
> I need help formatting an array to store the following date ranges per room.
>
> DATABASE Format
> Room StartDate EndDate
> ------------------------------------------------------------------------------
> Blue 10/23/2006 2/2/2007
> Green 10/25/2006 10/26/2006
> Yellow 11/2/2006 11/2/2006
> Yellow 11/10/2006 11/13/2007
>
> I am trying to use the following loop to get the ranges for each room, but how
> then do I apply that to an array for each record of each room and then append
> to the array.
>
> <cfloop from="#GetDays.StartDate#" to="#GetDays.EndDate#" index="x">
> <cfoutput>#dateformat(x, "MM/DD/YYYY")#</cfoutput><br>
> </cfloop>
>
> Thanks in advance for any help!!
>
>
July 26, 2006
Thanks Ian.

What I am trying to do is get this data in a managable format. If you take the example data from my first post, I need to create an array that appends to itself that gives me all the days that a specific room is available.

Expected Results:

Room Availability
-----------------------------------------------------------------------------------
Blue 10/23, 10/24, 10/25, 10/26, ... 2/1, 2/2
Green 10/25, 10/26
Yellow 11/2, 11/10, 11/12, 11/13

Hope that explains it better!