• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Structure/Array Help

Guest
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied



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!!
TOPICS
Advanced techniques

Views

660

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied

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!!
>
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied

Depending on how you want to structure your data, you should be able to
modify this code.

<cfset availibilityStruct = structNew()>

<cfloop query="getDays">
<cfset daysAvailList = "">
<cfset loopDate = parseDate(getdays.startDate)>
<cfset endDate = parseDate(getdays.endDate)>

<cfloop condition="#dateCompare(loopDate, endDate, "d") GT 0#">
<cfset daysAvailList = listAppend(daysAvailList,
dateFormat(loopDate, "mm/dd/yyyy")>
<cfset LoopDate = dateAdd("d", 1, LoopDate)>
</cfloop>

<cfif structKeyExists(availibilityStruct, getdays.room)>
<cfset availibilityStruct[getdays.room] =
listAppend(availibilityStruct[getdays.room], daysAvailList)>
<cfelse>
<cfset availibilityStruct[getdays.room] = daysAvailList>
</cfelse>
</cfloop>

This is not debugged or proofed so use accordingly.

DJ5MD wrote:
> 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!
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 27, 2006 Jul 27, 2006

Copy link to clipboard

Copied



Ian, I think you are oin the right track.

However, I am getting the following error, Any ideas?

Invalid CFML construct found on line 23 at column 84.
ColdFusion was looking at the following text:
>

The CFML compiler was processing:

an expression beginning with "ListAppend", on line 23, column 24.This message is usually caused by a problem in the expressions structure.
a cfset tag beginning on line 23, column 2.
a cfset tag beginning on line 23, column 2.
a cfset tag beginning on line 23, column 2.

<!--- Creates new Structure to hold data --->
<cfset availibilityStruct = StructNew()>

<cfloop query="GetDays">

<cfset daysAvailList = "">
<cfset LoopDate = parseDate(GetDays.StartDate)>
<cfset EndDate = parseDate(GetDays.EndDate)>

<cfloop condition="#DateCompare(LoopDate, EndDate, "d") GT 0#">
<cfset daysAvailList = ListAppend(daysAvailList, DateFormat(LoopDate, "mm/dd/yyyy")>
<cfset LoopDate = dateAdd("d", 1, LoopDate)>
</cfloop>

<cfif structKeyExists(availibilityStruct, GetDays.room)>
<cfset availabilityStruct[GetDays.Room] = listAppend(availabilityStruct[GetDays.Room] - daysAvailList>
<cfelse>
<cfset availabilityStruct[GetDays.Room] = daysAvailList>
</cfif>

</cfloop>

<cfdump var="#AvailabilityStruct#">
<cfabort>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 27, 2006 Jul 27, 2006

Copy link to clipboard

Copied

As I said, that was untested and unproofed code.

There are two left parentheses "(" but only one right parentheses ")"
on that line.

Properly close both functions on that line should remove this error.

DJ5MD wrote:
>
>
> Ian, I think you are oin the right track.
>
> However, I am getting the following error, Any ideas?
>
> Invalid CFML construct found on line 23 at column 84.
> ColdFusion was looking at the following text:
> >
>
> The CFML compiler was processing:
>
> an expression beginning with "ListAppend", on line 23, column 24.This message
> is usually caused by a problem in the expressions structure.
> a cfset tag beginning on line 23, column 2.
> a cfset tag beginning on line 23, column 2.
> a cfset tag beginning on line 23, column 2.
>
> <!--- Creates new Structure to hold data --->
> <cfset availibilityStruct = StructNew()>
>
> <cfloop query="GetDays">
>
> <cfset daysAvailList = "">
> <cfset LoopDate = parseDate(GetDays.StartDate)>
> <cfset EndDate = parseDate(GetDays.EndDate)>
>
> <cfloop condition="#DateCompare(LoopDate, EndDate, "d") GT 0#">
> <cfset daysAvailList = ListAppend(daysAvailList, DateFormat(LoopDate,
> "mm/dd/yyyy")>

> <cfset LoopDate = dateAdd("d", 1, LoopDate)>
> </cfloop>
>
> <cfif structKeyExists(availibilityStruct, GetDays.room)>
> <cfset availabilityStruct[GetDays.Room] =
> listAppend(availabilityStruct[GetDays.Room] - daysAvailList>
> <cfelse>
> <cfset availabilityStruct[GetDays.Room] = daysAvailList>
> </cfif>
>
> </cfloop>
>
> <cfdump var="#AvailabilityStruct#">
> <cfabort>
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 27, 2006 Jul 27, 2006

Copy link to clipboard

Copied

No problem, Ian. Got it.

What does parseDate refer to? I'm not familier with that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 27, 2006 Jul 27, 2006

Copy link to clipboard

Copied

LATEST
parseDateTime (that's what I get for not looking at the documentation
before I reply) converts a string into a date object.

DJ5MD wrote:
> No problem, Ian. Got it.
>
> What does parseDate refer to? I'm not familier with that.

ParseDateTime
Description
Parses a date/time string according to the English (U.S.) locale
conventions. (To format a date/time string for other locales, use the
LSParseDateTime function.)

Returns
A date/time object

Category
Date and time functions, Display and formatting functions

Function syntax
ParseDateTime(date/time-string [, pop-conversion ] )
See also
IsDate, IsNumericDate, SetLocale

Parameters
Parameter
Description

date/time string
A string containing a date/time value formatted according to U.S.
locale conventions. Can represent a date/time in the range 100 AD�9999
AD. Years 0-29 are interpreted as 2000-2029; years 30-99 are interpreted
as 1930-1999.

pop-conversion
pop: specifies that the date/time string is in POP format, which
includes the local time of the sender and a time-zone offset from UTC.
ColdFusion applies the offset and returns a value with the UTC time.
standard: (the default) function does no conversion.


Usage
This function is similar to CreateDateTime, but it takes a string
instead of enumerated date/time values. These functions are provided
primarily to increase the readability of code in compound expressions.

To calculate a difference between time zones, use the GetTimeZoneInfo
function.

To set the default display format of date, time, number, and currency
values, use the SetLocale function.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied



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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 26, 2006 Jul 26, 2006

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation