Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
schaudry #1
Date/Time Check with Arrays
Hello all, I have a site setup for registering for seminars. You click on a
button to add a seminar, and it adds it as a new structure in an array called
session.semcart. I was wondering if anyone knew a way to check the date and
time fields to see if someone registered for seminars occuring at the same
time. If they did, I would like a message to come up saying that they have
registered for overlapping seminars, and give them the option to remove one
from their cart. Here's the code that add's the seminar to the array, and the
page that displays the data in the array. Any help would be greatly
appreciated. addtocart.cfm ------------------------ <cfquery
name='getActDesc' datasource='seminar'> SELECT * FROM ActivityListingT WHERE
ActID = '#url.ActID#' </cfquery> <cfif IsDefined('session.semcart') is 'NO'>
<cfset session.semcart = arrayNew(1)> </cfif> <cfset newitem = 0> <cfloop
from='1' to='#arrayLen(session.semcart)#' index='i'> <cfif
session.semcart.ActID EQ #url.ActID#> <cfset newitem = 1> <cfbreak> </cfif>
</cfloop> <cfif newitem EQ 0> <cfset temp = arrayAppend(session.semcart,
structNew())> <cfset session.semcart[arrayLen(session.semcart)].ActID =
#getActDesc.ActID#> <cfset session.semcart[arrayLen(session.semcart)].ActDescr
= #getActDesc.ActDescr#> <cfset
session.semcart[arrayLen(session.semcart)].ActDate = #getActDesc.ActDate#>
<cfset session.semcart[arrayLen(session.semcart)].ActTime =
#getActDesc.ActTime#> <cfset session.semcart[arrayLen(session.semcart)].ActRoom
= #getActDesc.ActLocation#> <cfset
session.semcart[arrayLen(session.semcart)].ActCost = #getActDesc.ActCost#>
<cfset session.semcart[arrayLen(session.semcart)].Quantity = '1'> </cfif>
<script> self.location='cart.cfm'; </script>
--------------------------------------------------------------------------------
------------------- cart.cfm ---------------------------- <cfif
IsDefined('session.semcart') is 'NO'> You are currently not signed up for any
Seminars. <cfelse> <cfset totalItems = 0> <cfloop from='1'
to='#arrayLen(session.semcart)#' index='i'> <cfset totalItems =
variables.totalItems + session.semcart.Quantity> </cfloop> <cfif totalItems EQ
0> You are currently not signed up for any Seminars. <cfelse> <p> <table
width='90%' align='center' border='0' cellpadding='2' cellspacing='0'
style='border:2px solid #DDDDDD;'> <tr> <td colspan='7'
style='font-weight:bold;font-size:11pt;background-color:#DDDDDD'>Currently
Added Seminars</td> </tr> <tr> <td><b>ActID</b></td>
<td><b>Title</b></td> <td><b>Date</b></td>
<td><b>Time</b></td> <td><b>Cost</b></td>
<td><b>Action</b></td> </tr> <cfoutput> <cfloop from='1'
to='#arrayLen(session.semcart)#' index='i'> <cfset total =
session.semcart.ActCost> <tr style='background-color:##<cfif i MOD
2>EFEFEF<cfelse>FFFFFF</cfif>;'> <td>#session.semcart.ActID#</td>
<td>#session.semcart.ActDescr#</td>
<td>#DateFormat(session.semcart.ActDate, 'DDDD, MMMM DD, YYYY')#</td>
<td>#session.semcart.ActTime#</td>
<td>#DollarFormat(session.semcart.ActCost)#</td> <td><a
href='delete_seminar.cfm?ID=#i#'>Remove Seminar</a></td>
</tr> </cfloop> </cfoutput> <cfset totalprice = 0>
<cfloop from='1' to='#arrayLen(session.semcart)#' index='i'> <cfset
totalprice = variables.totalprice + total> </cfloop> <tr
style='background-color:#DDDDDD;'> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td>
<td><b><cfoutput>#DollarFormat(variables.totalpric e)#</cfoutput></b></td>
<td><a href='checkout.cfm'><b>Checkout</b></a></td> </tr>
</table> <p> You currently have
<cfoutput><strong>#variables.totalItems#</strong></cfoutput> <cfif
variables.totalItems EQ 1>item<cfelse>items</cfif> in your cart.<br> <a
href='checkout.cfm'><b>Proceed to Checkout >></b></a> <p> <a
href='clear_cart.cfm'>Remove all Seminars</a> </cfif> </cfif>
--------------------------------------------------------------------------------
-----------------------
schaudry Guest
-
Sanity check: Date::Manip versus summer time
All, I have been using Date::Manip for convenient and flexible (though heavyweight) time input, and I have discovered a behaviour that I find... -
CFMX7.0.1 Administrator date time issue showing 13hrsbehind server time
I am running a W2k SP4 box that has been upgraded from CFMX6 to CFMX7.0.1. The CFMX7.0.1 server is showing the date on the Server Settings >... -
to check to date must be greater or equal from date
Hi All, I code my date selection like this : <select name="day" class="formData"> <cfloop index="d" from="1" to="31" step="+1"> <option... -
Convert date/time to date in SQL Server 2000 statement
Can this be done? tia -
check the time and date
Hi, Can anyone help me to solve the following task. I want to ask perl to launch certain software and normally, we use system command, right?... -
schaudry #2
Re: Date/Time Check with Arrays
Does no one know how to do this? Or am I being unclear as to what i'm trying to
do? Basically, I want to check to see if Seminar 1 in the array is at the
same time as Seminar 2. I'm not even sure how to begin to do this. Any help
would be greatly appreciated.
schaudry Guest
-
schaudry #3
Re: Date/Time Check with Arrays
Well, no one seems to have responded so I'll make the question a little easier
to understand. Does anyone know how to check if two structures in an array
have the same variable? For instance, if there is a variable that says
ActTimeSlot and its value is 1, how can I check to see if it is in both
structures? If two structures display 1 under ActTimeSlot, I want it to display
a message that the two activities are at the same time. Please help, I've been
struggling with this for quite some time now. Thanks.
schaudry Guest
-
The ScareCrow #4
Re: Date/Time Check with Arrays
Asumming you have
Struct1 and Struct2
Then check if the key exists in both structures
<cfif StructKeyExists(Struct1, "ActTimeSlot") And StructKeyExists(Struct2,
"ActTimeSlot")>
<!--- then compare the values --->
<cfif StructFind(Struct1, "ActTimeSlot") IS StructFind(Struct2, "ActTimeSlot")>
Then they equeal
<cfelse>
They are different
</cfif>
<cfelse>
Key does not exist...
</cfif>
Ken
The ScareCrow Guest
-
schaudry #5
Re: Date/Time Check with Arrays
Thanks for replying Ken, I was wondering, what if there were more than one
structure? As each new seminar is added, it becomes a new structure. Is there a
way to write the statement above so that it would check the newest added
structure against the existing structures? Say if there are 3 structures, and a
fourth was added, how would i loop through the array to see if there was a
duplicate key? Thanks for your help with this.
schaudry Guest
-
The ScareCrow #6
Re: Date/Time Check with Arrays
If I understand this correctly:
As the structures are added to an array, you would need to loop through the
array.
Smething like the attached code, but be aware this is only sudo code.
Ken
<!--- only need to check if there is more than one --->
<cfif ArrayLen(Array) GT 1>
<cfset lastStruct = ArrayLen(Array)>
<cfloop from="1" to="ArrayLen(Array)-1" index="idx">
<cfset nextStruct = "Struct#idx#">
<cfif StructKeyExists(nextStruct, "ActTimeSlot") And
StructKeyExists(lastStruct, "ActTimeSlot")>
<!--- then compare the values --->
<cfif StructFind(nextStruct, "ActTimeSlot") IS StructFind(lastStruct,
"ActTimeSlot")>
Then they equeal
<cfelse>
They are different
</cfif>
<cfelse>
Key does not exist...
</cfif>
</cfloop>
</cfif>
The ScareCrow Guest
-
schaudry #7
Re: Date/Time Check with Arrays
thanks again for replying. I tried the code you wrote with a few changes, but I
keep getting the following error: 'You have attempted to dereference a scalar
variable of type class java.lang.String as a structure with members.' Here's
the code that I added to my cart.cfm page: <cfif ArrayLen(session.semcart) GT
1> <cfset lastStruct = ArrayLen(session.semcart)> <cfloop from='1'
to='#ArrayLen(session.semcart)#-1' index='i'> <cfset nextStruct = 'Struct#i#'>
<cfif StructKeyExists(nextStruct, 'ActTimeSlot') And
StructKeyExists(lastStruct, 'ActTimeSlot')> <!--- then compare the values --->
<cfif StructFind(nextStruct, 'ActTimeSlot') IS StructFind(lastStruct,
'ActTimeSlot')> <cfset message = 'Two or more seminars are at the same time,
please look over your registration and remove the duplicates'> <cfelse>
<cfset message = ''> </cfif> </cfif> </cfloop> </cfif>
schaudry Guest
-
The ScareCrow #8
Re: Date/Time Check with Arrays
As I said this was only psudo code, you will need to check for the correct
syntax, but
I don't think this is correct in the loop #ArrayLen(session.semcart)#-1
You will most probably need to set a var and use that in the loop.
Also, I'm not sure the following is valid
StructKeyExists(nextStruct, "ActTimeSlot")
You may need to enclose in #'s
You will need to check the doc's for this.
Ken
The ScareCrow Guest



Reply With Quote

